@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds => ds.URL("/Home/DataSource1").Adaptor(AdaptorType.UrlAdaptor))
.AllowFiltering()
.AllowPaging()
.ClientSideEvents(e=>e.ActionBegin("onActionBegin"))
.FilterSettings(f=>f.FilterType(FilterType.Excel).MaxFilterChoices(25))
.Columns(col =>
{
col.Field("OrderID").HeaderText("OrderID").Add();
col.Field("CustomerID").HeaderText("Customer ID").Width(100).Add();
col.Field("Freight").Width(120).Add();
col.Field("ShipName").Width(100).Add();
})
)
<script>
function onActionBegin(args) {
if (args.requestType == "filterchoicerequest") {
//selects only the filtering column
//which prevents the serialization errror.
args.query.select(args.filterModel.fName);
}
}
</script>
public ActionResult DataSource1(Syncfusion.JavaScript.DataManager dm)
{
IEnumerable datasource = OrderRepository.GetAllRecords();
DataOperations operation = new DataOperations();
if (dm.Where != null)//for filtering
datasource = operation.PerformWhereFilter(datasource, dm.Where, dm.Where[0].Condition);
//selects only the required columns
if (dm.Select != null)
{
datasource = operation.PerformSelect(datasource, dm.Select);
/*
convert dataSource to the distinct set of the records based on the dm.Select value
*/
}
int count = datasource.AsQueryable().Count();
if (dm.Skip >= 0)//for paging
datasource = operation.PerformSkip(datasource, dm.Skip);
if (dm.Take > 0)//for paging
datasource = operation.PerformTake(datasource, dm.Take);
return Json(new { result = datasource, count = count });
} |