We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Auto Increment Column in Ej Grid

I want an auto increment column in my grid.When i add a row ,the field must be added automatically.How can i do that ?

4 Replies

AS Alan Sangeeth S Syncfusion Team March 5, 2015 08:47 AM UTC

Hi Ganga,

Thanks for using Syncfusion Products.

We would like to let you know that, in server-side CRUD operation with an Identity Column in database table, we can have auto increment Grid column using “IsIdentity” Grid Column Property. Please refer the following code snippets.

@(Html.EJ().Grid<EJGrid.Models.Order>("FlatGrid")

...

.Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsIdentity(true).IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

...

})

 During add operation, the Identity column would be disabled and on save, the record would be updated with the incremented value obtained from server-side database.

Also For your information, that until Essential Studio version 12.4.0.30 we had issue with “Primary Key value becomes empty after adding a record when IsIdentity property is set as true” and it is now has been fixed in our latest version 12.4.0.34 which can be downloaded from below link.

http://www.syncfusion.com/forums/118366/essential-studio-2014-volume-4-service-pack-2-release-v12-4-0-34-available-for-download

If we misunderstood your requirement or you would like to use only client-side CRUD operation then please get back to us so that we could provide you a response as early as possible.

Please let us know if you have any queries.

Regards,
Alan Sangeeth S




JK Jitender Kumar replied to Alan Sangeeth S May 10, 2016 04:42 AM UTC

Hi Ganga,

Thanks for using Syncfusion Products.

We would like to let you know that, in server-side CRUD operation with an Identity Column in database table, we can have auto increment Grid column using “IsIdentity” Grid Column Property. Please refer the following code snippets.

@(Html.EJ().Grid<EJGrid.Models.Order>("FlatGrid")

...

.Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsIdentity(true).IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

...

})

 During add operation, the Identity column would be disabled and on save, the record would be updated with the incremented value obtained from server-side database.

Also For your information, that until Essential Studio version 12.4.0.30 we had issue with “Primary Key value becomes empty after adding a record when IsIdentity property is set as true” and it is now has been fixed in our latest version 12.4.0.34 which can be downloaded from below link.

http://www.syncfusion.com/forums/118366/essential-studio-2014-volume-4-service-pack-2-release-v12-4-0-34-available-for-download

If we misunderstood your requirement or you would like to use only client-side CRUD operation then please get back to us so that we could provide you a response as early as possible.

Please let us know if you have any queries.

Regards,
Alan Sangeeth S



Hi Alan Sangeeth,
I am using Syncfusion 14.1400.0.41, but getting the same problem as you have mentioned in 12.4.0.30.  My columns is as below 
col.Field("Id").HeaderText("ID").IsIdentity(true).IsPrimaryKey(true).Visible(false).Add();
But it is also not working while setting columns Visible true.Primary columns always show empty column.

Please suggest as soon as possible. 

Thanks & Regards,
Jitender


CS Cody S May 10, 2016 06:57 PM UTC

I'm also having this issue. When adding an item and IsIdentity is true, the value is null until the page is refreshed. When you add an item and try to delete it, the delete fails because the ID field on the grid is null (again, once the page is refreshed, the ID has the correct value and can than be deleted).

It seems to be with the grid logic because when you add an item to the grid, the record in the database gets the appropriate ID but the grid doesn't retrieve and display it.


VA Venkatesh Ayothi Raman Syncfusion Team May 11, 2016 01:04 PM UTC

Hi Cody/Jitender, 

Thanks for the update. 

If we enable the IsIdentity property for a column then we must handle auto increment column. Example if we bound the local data source, then we have to increment the IsIdentity field in some events like actionBegin(on save) or if we bound the remote data source for the Grid, then we have to return the modified data with Isdentity field value while adding the record. So, we are the responsibility to handle the Isidentity column. 

We have created a sample for your requirement. In this sample, we bound the list datasource to the Grid and increment the count value itself for Isdentity column while adding the new record. Please refer to the sample, 



Regards, 
Venkatesh Ayothiraman. 


Loader.
Live Chat Icon For mobile
Up arrow icon