@(Html.EJ().Grid<object>("Grid")
.Datasource(ds => ds.URL("/Home/DataSource").Adaptor("UrlAdaptor"))
.AllowPaging()
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Search);
});
})
.Columns(col =>
{
...
}) ) |
[HomeController.cs]
public ActionResult DataSource(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(DataManager dm)
{
IEnumerable data = OrderRepository.GetAllRecords().ToList();
DataOperations operation = new DataOperations();
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
data = operation.PerformSorting(data, dm.Sorted);
}
if (dm.Search != null && dm.Search.Count > 0)
{
Data = operation.PerformSearching(Data, dm.Search); //perform search operation in grid.
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
data = operation.PerformWhereFilter(data, dm.Where, dm.Where[0].Operator);
}
int count = data.Cast<EditableOrder>().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 });
}
public class DataResult
{
public IEnumerable result { get; set; }
public int count { get; set; }
}
|