|
HomeController.cs
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
IEnumerable DataSource = Utils.DataTableToJson(dt); //Here dt is the dataTable
DataOperations operation = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = operation.PerformSearching(DataSource, dm.Search); //Search
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = operation.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
List<string> str = new List<string>();
if (dm.Aggregates != null)
{
for (var i = 0; i < dm.Aggregates.Count; i++)
str.Add(dm.Aggregates[i].Field);
}
IEnumerable aggregate = operation.PerformSelect(DataSource, str);
int count = DataSource.Cast<object>().Count();
if (dm.Skip != 0)
{
DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? Json(new { result = DataSource, count = count, aggregate = aggregate }) : Json(DataSource);
}
|
|
<ejs-grid id="Grid" allowPaging="true">
<e-data-manager url="@Url.Action("UrlDataSource", "Home")" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-pagesettings pageCount="5" pageSize="10"></e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="orderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="125"></e-grid-column>
<e-grid-column field="customerID" headerText="Customer Name" width="150"></e-grid-column>
<e-grid-column field="employeeID" headerText="Employee ID" width="150"></e-grid-column>
<e-grid-column field="orderDate" headerText=" Order Date" format="yMd" width="130"></e-grid-column>
</e-grid-columns>
</ejs-grid> |