View side:- <ej-grid id="Grid" datasource=ViewBag.data allow-paging="true"> <e-datamanager url="/Home/DataSource"adaptor="UrlAdaptor" /> <e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" "></e-edit-settings> <e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"add","edit","update","cancel"}' /> <e-columns> <e-column header-text="Order ID" field="OrderID" is-primary-key="true" is-identity="true" /> <e-column header-text="Customer ID" field="CustomerID" /> <e-column header-text="Employee ID" field="EmployeeID" /> <e-column header-text="Freight" field="Freight" format="{0:C2}" /> </e-columns> </ej-grid> Controller side:- public ActionResult DataSource([FromBody]DataManager dm) { IEnumerable data = order; DataOperations operation = new DataOperations(); if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting { data = operation.PerformSorting(data, dm.Sorted); } if (dm.Where != null && dm.Where.Count > 0) //Filtering { data = operation.PerformWhereFilter(data, dm.Where, dm.Where[0].Operator); } int count = data.Cast<Orders>().Count(); if (dm.Skip != 0) { data = operation.PerformSkip(data, dm.Skip); } if (dm.Take != 0) { data = operation.PerformTake(data, dm.Take); } return Json(new { result = data, count = count }); } |
Hi Morgan,
Thanks for contacting syncfusion support.
We have created sample according to your requirement which can be downloaded from the below location.
In this sample, we have used “UrlAdaptor” of ejDataManger when binding datasource from remote data. While passing parameter to DataManager class for performing serverside operation, you have to use [FromBody] in front of the parameter i. e. ([FromBody]DataManager dm).
Please refer to the code example:-
View side:-<ej-grid id="Grid" datasource=ViewBag.data allow-paging="true"><e-datamanager url="/Home/DataSource"adaptor="UrlAdaptor" /><e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" "></e-edit-settings><e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"add","edit","update","cancel"}' /><e-columns><e-column header-text="Order ID" field="OrderID" is-primary-key="true" is-identity="true" /><e-column header-text="Customer ID" field="CustomerID" /><e-column header-text="Employee ID" field="EmployeeID" /><e-column header-text="Freight" field="Freight" format="{0:C2}" /></e-columns></ej-grid>
Controller side:-public ActionResult DataSource([FromBody]DataManager dm){IEnumerable data = order;DataOperations operation = new DataOperations();if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting{data = operation.PerformSorting(data, dm.Sorted);}if (dm.Where != null && dm.Where.Count > 0) //Filtering{data = operation.PerformWhereFilter(data, dm.Where, dm.Where[0].Operator);}int count = data.Cast<Orders>().Count();if (dm.Skip != 0){data = operation.PerformSkip(data, dm.Skip);}if (dm.Take != 0){data = operation.PerformTake(data, dm.Take);}return Json(new { result = data, count = count });}
Regards,
Farveensulthana T