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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

128246 Jan 10,2017 01:11 PM Jan 11,2017 07:38 AM ASP.NET MVC 2
loading
Tags: Grid
Steve Lei
Asked On January 10, 2017 01:11 PM

Hi,

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.

Thanks.

Attachment: Syncfusion_Grid_Deletion_f49c6ded.zip

Steve Lei
Replied On January 10, 2017 01:29 PM

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)
                                  .AllowPaging()
                                  .AllowTextWrap()
                                  .TextWrapSettings(wrap => { wrap.WrapMode(WrapMode.Both); })
                                  .EditSettings(edit => { edit.AllowDeleting().AllowEditing().ShowDeleteConfirmDialog(); })
                                  .ToolbarSettings(toolbar =>
                                  {
                                      toolbar.ShowToolbar().ToolbarItems(items =>
                                      {
                                          items.AddTool(ToolBarItems.Edit);
                                          items.AddTool(ToolBarItems.Delete);
                                      });
                                  })
                                  .Columns(col =>
                                  {
                                      col.Field("Id").Visible(false).IsPrimaryKey(true).Add();
                                      col.Field("ModelNumber").HeaderText("Model Number").Width(130).Add();
                                      col.Field("Description").HeaderText("Description").Add();
                                      col.Field("Amount").HeaderText("Amount").TextAlign(TextAlign.Right).Type(ColumnType.Number).Format("{0:C}").Width(75).Add();
                                      col.Field("Quantity").HeaderText("Quantity").TextAlign(TextAlign.Center).Width(75).Add();
                                      col.Field("Total").HeaderText("Total").TextAlign(TextAlign.Right).Type(ColumnType.Number).Format("{0:C}").Width(75).Add();
                                  })
                                  )

Mani Sankar Durai [Syncfusion]
Replied On January 11, 2017 07:38 AM

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. 
 
Regards,  
Manisankar Durai 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;