}
View:;
@{ Html.EJ().Grid<Chemical>("ChemicalGrid") .Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource).UpdateURL("/Chemicals/Update") .InsertURL("/Chemicals/Insert").RemoveURL("/Chemicals/Remove").Adaptor(AdaptorType.RemoteSaveAdaptor)) .AllowSorting() .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) .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() .AllowMultiSorting() .SortSettings(sort => { sort.SortedColumns(col => col.Field("ChemicalId"). .Columns(col => { col.Field("ChemicalId").HeaderText("Id").IsPrimaryKey(true).TextAlign(TextAlign.Right).Add(); col.Field("ChemicalStation").HeaderText("Station").EditType(EditingType.String).ValidationRules(v => v.AddRule("required", true).AddRule("minlength", 2)).TextAlign(TextAlign.Right).Add(); col.Field("ChemicalDistance").HeaderText("Distance").EditType(EditingType.Numeric).NumericEditOptions(new EditorProperties() { DecimalPlaces = 2, }).TextAlign(TextAlign.Right).Add(); col.Field("ChemicalBod").HeaderText("Bod").EditType(EditingType.Numeric).NumericEditOptions(new EditorProperties() { DecimalPlaces = 2, }).TextAlign(TextAlign.Right).Add(); col.Field("ChemicalDo").HeaderText("Do").EditType(EditingType.Numeric).NumericEditOptions(new EditorProperties() { DecimalPlaces = 2, }).TextAlign(TextAlign.Right).Add(); col.Field("ChemicalQ").HeaderText("Q").EditType(EditingType.Numeric).NumericEditOptions(new EditorProperties() { DecimalPlaces = 2, }).TextAlign(TextAlign.Right).Add(); }) .Render(); }
On performing CRUD operations in Grid, the record changes will be sent to server-side as in the following screenshot.
{Html.EJ().Grid<Object>("FlatGrid")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.data).UpdateURL("/Home/CellEditUpdate").InsertURL("/Home/CellEditInsert").RemoveURL("/Home/CellEditDelete").Adaptor(AdaptorType.RemoteSaveAdaptor))
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
.AllowPaging()
..
}).Render();
}
HomeController.cs
namespace WebApplication8.Controllers
{
public class HomeController : Controller
{
..
public ActionResult CellEditUpdate([FromBody]CRUDModel<Orders> value)
{
// do your operations here
}
public ActionResult CellEditInsert([FromBody]CRUDModel<Orders> value)
{
// do your operations here
}
public ActionResult CellEditDelete([FromBody]CRUDModel<Orders> value)
{
// do your operations here
}
}
}
|