public
ActionResult DataSource(DataManager data)
{
IQueryable<OrdersView> datasource =
new
NorthwindDataContext().OrdersViews;
var count = datasource.AsQueryable().Count();
var dm = QueryableDataOperations.Execute(datasource, data);
return
Json(
new
{ result = dm, count = count });
}
// View page
@(Html.EJ().Grid<object>("CellMerging")
.Datasource(ds => ds.URL("/Grid/DataSource").Adaptor("UrlAdaptor"))
.AllowFiltering()
.AllowSorting() /*Sorting Enabled*/
.AllowPaging() /*Paging Enabled*/
.Columns(col =>
{
……………
}))
// Controller Page
public ActionResult GridFeatures()
{
return View();
}
public ActionResult DataSource(DataManager data)
{
IQueryable<OrdersView> datasource = new NorthwindDataContext().OrdersViews;
var count = datasource.AsQueryable().Count();
var dm = QueryableDataOperations.Execute(datasource, data);
if (data.Where != null || data.Search != null || data.Sorted != null)
count = dm.Count();
return Json(new { result = dm, count = count });
} |
public ActionResult DataSource([FromBody]DataManager data)
{
IQueryable<OrdersView> datasource = new NorthwindDataContext().OrdersViews;
if (data.Where != null) // for filtering
datasource = QueryableDataOperations.PerformWhereFilter(datasource, data.Where, data.Where[0].Condition);
if (data.Sorted != null)//for sorting
datasource = QueryableDataOperations.PerformSorting(datasource, data.Sorted);
if (data.Search != null)
datasource = QueryableDataOperations.PerformSearching(datasource, data.Search);
int count = datasource.Count();
if (data.Skip >= 0)//for paging
datasource = QueryableDataOperations.PerformSkip(datasource, data.Skip);
if (data.Take > 0)//for paging
datasource = QueryableDataOperations.PerformTake(datasource, data.Take);
return Json(new { result = datasource.ToList(), count = count }, JsonRequestBehavior.AllowGet);
} |
public ActionResult UrlDataSource([FromBody]DataManager data)
{
IQueryable<OrdersView> datasource = new NorthwindDataContext().OrdersViews;
var count = datasource.Count();
datasource = QueryableDataOperations.Execute(datasource, dm);
if (data.Where != null) // to update the count value while filtering
{
IQueryable<OrdersView> data = QueryableDataOperations.PerformWhereFilter(new NorthwindDataContext().OrdersViews, data.Where, data.Where[0].Condition);
count = data.Count();
}
if (data.Search != null)// to update the count value while searching
{
IQueryable<OrdersView> data = QueryableDataOperations.PerformSearching(new NorthwindDataContext().OrdersViews, data.Search);
count = data.Count();
}
return Json(new { result = datasource, count = count });
} |