<ej-grid id="FlatGrid" allow-paging="true" allow-filtering="true" >
<e-filter-settings filter-type="Excel"></e-filter-settings>
<e-datamanager url="/Home/DataSource" adaptor="UrlAdaptor"></e-datamanager>
<e-columns>
<e-column field="OrderID" header-text="Order ID" is-primary-key="true" text-align="Right" width="75"></e-column>
<e-column field="CustomerID" header-text="Customer ID" width="75"></e-column>
<e-column field="ShipCity" header-text="Ship City" width="75"></e-column>
</e-columns>
</ej-grid> |
[HomeController.cs]
public ActionResult DataSource([FromBody]DataManager dm)//Using DataManager class which contains Sorting, filtering as a parameter.
{…. } |
using Syncfusion.JavaScript.DataSources;
using Syncfusion.Linq;
using Syncfusion.JavaScript.Models;
public ActionResult DataSource([FromBody]DataManager dm)
{
IEnumerable data = orddata;
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 });
}
|