<button id="btn" onclick="Save()">Click to save changes</button>
@(Html.EJ().Grid<MvcApplication14.OrdersView>("FlatGrid")
.Datasource(ds => ds.URL("/Grid/Data")
.BatchURL("/Grid/BatchUpdate")
.Adaptor(AdaptorType.UrlAdaptor))
.ClientSideEvents(eve => eve. ActionBegin("begin") ActionComplete("complete"))
.Columns(col =>
...
})
)
<script type="text/javascript">
var batch = null;
function begin(args) {
var grid = $("#FlatGrid").ejGrid("instance");
if (args.requestType = "paging") {
batch = this.batchChanges;
}
}
function complete(args) {
var grid = $("#Grid").ejGrid("instance");
if (args.requestType = "paging") {
if ( batch != null)
this.batchChanges = batch;
}
}
function Save() {
var grid = $("#FlatGrid").ejGrid("instance");
grid.batchSave();
}
</script>
[GridController.cs]
public ActionResult BatchUpdate(List<EditableOrder> added, List<EditableOrder> changed, List<EditableOrder> deleted, int? key)
{
if (changed != null)
OrderRepository.Update(changed);
if (deleted != null)
OrderRepository.Delete(deleted);
if (added != null)
OrderRepository.Add(added);
var data = OrderRepository.GetAllRecords();
return Json(data, JsonRequestBehavior.AllowGet);
} |
function Save() {
var grid = $("#FlatGrid").ejGrid("instance");
grid.batchChanges.added.push("//add the new data which is in array");
grid.batchSave(); |
function complete(args) {
var grid = $("#Grid").ejGrid("instance");
if (args.requestType == "paging") {
if (batch != null)
this.batchChanges = batch;
}
if (args.requestType == "batchsave") {
alert("saved sucess")
}
}
function failure(args) {
var str = "";
str = args.error.statusText;
alert(str);
} |