| @(Html.EJ().Grid<Object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.DataSource) .AllowPaging() .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) .ClientSideEvents(eve => eve.ActionComplete("Complete").ActionBegin("Begin")) .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); }); }) .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add(); col.Field("CustomerID").HeaderText("Customer ID").Add(); col.Field("EmployeeID").HeaderText("Employee ID").Add(); col.Field("ShipCity").HeaderText("Ship City").Add(); col.Field("ShipCountry").HeaderText("Ship Country").Add(); })) <script> var flag; function Begin(args) { if (args.requestType == "add") flag = true; } function Complete(args) { if (args.requestType == "save") { if (flag) { this.model.dataSource.shift() // remove the newly added row this.model.dataSource.push(args.data) // push the added row at your required index this.refreshContent(); flag = false; } } } </script> |
| <div id="ControlRegion"> @(Html.EJ().Grid<object>("FlatGrid") .AllowPaging() .Datasource((IEnumerable<object>)ViewBag.datasource) .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch).RowPosition(RowPosition.Bottom); }) . . . . . .ClientSideEvents(e => e.CellSave("save")) .Columns(col => { . . . . . }))</div> <script> function save(args) { if (args.cell.closest("tr").index() + 1 == args.model.pageSettings.pageSize) { if (args.cell.index() + 1 == this.getVisibleColumnNames().length) { var proxy = this; setTimeout(function () { proxy.addRecord(); }, 0) } } } </script> |
| |
| @(Html.EJ().Grid<object>("Grid") .AllowPaging() .Datasource((IEnumerable<object>)ViewBag.datasource) .ClientSideEvents(eve => eve.ActionComplete("Complete").CellSave("save")) .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); })) <script> var data; function Complete(args) { if (args.requestType == "batchsave") { this.model.dataSource.splice(-1); var index = (this.model.pageSettings.currentPage * this.model.pageSettings.pageSize)-1; this.model.dataSource.splice(index, 0, data); this.refreshContent(); } } function save(args){ data = args.rowData; } </script> |