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

Delete row using build-in toolbar. But remove wrong row in datasource


When I trying to delete row in grid using build-in toolbar, the deletion display is correct. However, when I try get the datasource in jQuery, it seems remove wrong row in datasource.

For example, the product grid shows 2 products. If I delete 1st item, the display and datasource are sync. correctly. But if I delete 2nd item. The display is correct, but datasource is showing 1st itme data.

Here is how I get the datasource object in jQuery

var products = $("#InvoiceProducts").ejGrid("option", "dataSource");

I am using this is because I have save button for entire form. The controller will get all updated data and determine which row need to insert/update or delete.
Does additional call to make grid sync with datasource after deletion?

Attached is the screenshot document to explain more clearly.


Attachment: Syncfusion_Grid_Deletion_f49c6ded.zip

2 Replies

SL Steve Lei January 10, 2017 06:29 PM UTC

I think I may find out why delete the wrong one. I have to set the primarykey field to true.

@(Html.EJ().Grid<InvoiceProductServices>("InvoiceProducts").Datasource((IEnumerable<object>) Model.InvoiceProducts)
                                  .TextWrapSettings(wrap => { wrap.WrapMode(WrapMode.Both); })
                                  .EditSettings(edit => { edit.AllowDeleting().AllowEditing().ShowDeleteConfirmDialog(); })
                                  .ToolbarSettings(toolbar =>
                                      toolbar.ShowToolbar().ToolbarItems(items =>
                                  .Columns(col =>
                                      col.Field("ModelNumber").HeaderText("Model Number").Width(130).Add();

MS Mani Sankar Durai Syncfusion Team January 11, 2017 12:38 PM UTC

Hi Steve,  

Thanks for contacting Syncfusion support. 

Yes the primary key for the data source should be defined in Columns definition, for editing to work properly by enabling IsPrimaryKey property of columns in grid. We have already discussed about this in the following KB.  
Refer to the Help Documents and API Reference Section of the Grid.  
Also we have already documented about the necessity of IsPrimaryKey property of columns in the Editing section of the below document link.  
Please let us know if you need further assistance. 
Manisankar Durai 

Live Chat Icon For mobile
Up arrow icon