Index.cshtml
<ejs-grid id="Grid" allowPaging="true" load="onLoad" toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel"})">
<e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch"></e-grid-editsettings>
<e-data-manager url="/Index?handler=DataSource" batchUrl="/Index?handler=BatchUpdate" adaptor="UrlAdaptor"></e-data-manager>
. . .
</e-grid-columns>
</ejs-grid>
Index.cshtml.cs
public JsonResult OnPostBatchUpdate([FromBody]CRUDModel batchmodel)
{
if (batchmodel.Changed.Count != 0)
{
for (var i = 0; i < batchmodel.Changed.Count(); i++)
{
var ord = batchmodel.Changed[i];
Orders val = order.Where(or => or.OrderID == ord.OrderID).FirstOrDefault();
val.OrderID = ord.OrderID;
val.EmployeeID = ord.EmployeeID;
val.CustomerID = ord.CustomerID;
val.ShipCity = ord.ShipCity;
}
}
if (batchmodel.Deleted.Count != 0)
{
for (var i = 0; i < batchmodel.Deleted.Count(); i++)
{
order.Remove(order.Where(or => or.OrderID == batchmodel.Deleted[i].OrderID).FirstOrDefault());
}
}
if (batchmodel.Added.Count != 0)
{
for (var i = 0; i < batchmodel.Added.Count(); i++)
{
order.Insert(0, batchmodel.Added[i]);
}
}
var data = order.ToList();
return new JsonResult(data);
} |