<ejs-grid id="Grid" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<e-data-manager url="/home/UrlDatasource" batchUrl="/Home/BatchUpdate" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" width="150"></e-grid-column>
<e-grid-column field="EmployeeID" headerText="Employee ID" width="130" textAlign="Right"></e-grid-column>
<e-grid-column field="ShipCity" headerText="ShipCity" width="120"></e-grid-column>
</e-grid-columns>
</ejs-grid>
|
...
public IActionResult BatchUpdate([FromBody]CRUDModel batchmodel)
{
if (batchmodel.Changed != null)
{
for (var i = 0; i < batchmodel.Changed.Count(); i++)
{
...
}
}
if (batchmodel.Deleted != null)
{
for (var i = 0; i < batchmodel.Deleted.Count(); i++)
{
order.Remove(order.Where(or => or.OrderID == batchmodel.Deleted[i].OrderID).FirstOrDefault());
}
}
if (batchmodel.Added != null)
{
for (var i = 0; i < batchmodel.Added.Count(); i++)
{
order.Insert(0, batchmodel.Added[i]);
}
}
var data = order.ToList();
return Json(data);
} |
<ejs-grid id="Grid" actionComplete="complete" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<e-data-manager url="/home/UrlDatasource" batchUrl="/Home/BatchUpdate" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch"></e-grid-editSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
. . .
</e-grid-columns>
</ejs-grid>
<script>
function complete(e) {
if (e.requestType == 'batchsave') {
var ajax = new ej.base.Ajax();
ajax.url = "/Home/AfterSave";
ajax.type = "POST";
ajax.contentType = "application/json; charset=utf-8";
ajax.send().then(function (data) {
console.log(data);
});
}
}
</script> |
public class HomeController : Controller
{
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
IEnumerable DataSource = order;
. . .
return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
}
public IActionResult BatchUpdate([FromBody]CRUDModel batchmodel)
{
. . .
return Json(data);
}
public string AfterSave()
{
return "saved";
}
} |
|