Persist row reordering to DB

Hi,

We are making use of the grid to render a dataset which is loaded from the DB. We have enabled row reordering via drag and drop. Our objects contain an index property and we sort on that property before binding to the grid (i.e. sorting is not done via the grid)

Is there a way to persist the reordering that is done on the browser side to the DB? 

Thanks,
-Malcolm

1 Reply

VN Vignesh Natarajan Syncfusion Team October 23, 2018 10:18 AM UTC

Hi Malcolm, 
 
 
Thanks for contacting Syncfusion support. 
 
 
Query: “Is there a way to persist the reordering that is done on the browser side to the DB?” 
 
 
We can achieve your requirement using the RowDropMapper property of RowDropSettings of Grid. By using the RowDropMapper property, we can obtain the row data which is reordered and the destination row index. Please refer the below code example and screenshots for your reference. 
 
 
 
@(Html.EJ().Grid<OrdersView>("Grid") 
            .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource).Adaptor(AdaptorType.RemoteSaveAdaptor)) 
            .AllowSorting() 
            .AllowPaging() 
            .SelectionType(SelectionType.Multiple) 
            .AllowRowDragAndDrop() 
            .RowDropSettings(drop => drop.RowDropMapper("/Home/RowDropHandler")) 
            .Columns(col => 
            { 
                col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(55).Add(); 
                col.Field("CustomerID").HeaderText("Customer ID").Width(70).Add(); 
                col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(70).Add(); 
                col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(55).Add(); 
            }) 
) 
 
 
[controller] 
 
public ActionResult RowDropHandler(List<EditableOrder> changed, List<EditableOrder> added, List<EditableOrder> deleted) 
        { 
            JavaScriptSerializer ser = new JavaScriptSerializer(); 
            RowDropModel dropDetails = (RowDropModel)ser.Deserialize(Request.Headers["rowDropDetails"], typeof(RowDropModel)); 
 
                    ///// You can perform the required operations here. 
            
            return Json("success", JsonRequestBehavior.AllowGet); 
        } 
 
 
Please refer the below screenshots. 
 
  1. Data of the row which is reordered.
 
 
 
  1. Destination index.
 
 
 
 
Please refer the below link for the sample. 
 
 
 
 
Refer our help documentation from below link 
 
 
 
 
please get back to us if you have further queries. 
 
 
Regards, 
Vignesh Natarajan 
 


Loader.
Up arrow icon