@(Html.EJ().Grid<object>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); })
.ToolbarSettings(toolbar =>{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
.AllowPaging()
.ClientSideEvents(eve => { eve.CellSave("cellsave"); })
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add();
col.Field("CustomerID").HeaderText("Customer ID").Add();
. . .
})
)
<script type="text/javascript">
var flag = true;
function cellsave(args) {
if (flag) {
args.cancel = true;
if ($.inArray(args.rowData, this.batchChanges.changed) == -1 && $.inArray(args.rowData, this.batchChanges.added) == -1)
this.batchChanges.changed.push(args.rowData);
var batchData = this.getBatchChanges();
var batchDetails = this._bulkEditCellDetails;
if (batchData.added.length > 0 || batchData.changed.length > 0 || batchData.deleted.length > 0) {
flag = false;
this.batchSave();
this._bulkEditCellDetails = batchDetails;//reassigning the values
}
}
else
flag = true;
};
</script>
|