incremental row ID

Hi item,


Is there is the way to get incremented ID for added item automatically after I click AddItem button?


Image_1833_1740640367336

I'm using batch mode by the way.


Beast Regards,

Tyrone


1 Reply

SK Sanjay Kumar Suresh Syncfusion Team February 28, 2025 10:19 AM UTC

Hi Tyrone,


Yes, you can automatically assign new values to the primary key column using the DefaultValue property in the GridColumn. This property ensures that newly added rows receive a predefined value, making data entry more efficient.


Since your scenario involves batch editing, you can achieve this by handling the OnBatchAdd event. This event allows you to dynamically assign and increment values for the primary key column when new rows are added. Please refer to the following code snippet for implementation.


Concern Code Snippet:


<GridEvents OnBatchAdd="BatchAddHandler" TValue="Order"></GridEvents>

….

 

int incer = 16;

 

    public void BatchAddHandler(BeforeBatchAddArgs<Order> args)

    {

         args.DefaultData.OrderID= incer++;

    }

 



Playground Sample:

https://blazorplayground.syncfusion.com/embed/VXBJMiVaqdDHZvUN?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5


Additional References:

https://blazor.syncfusion.com/documentation/datagrid/events#onbatchadd


Please get back to us if you need any other assistance.



Regards,

Sanjay Kumar Suresh


Loader.
Up arrow icon