|
[index]
@{
List<string> toolbarItems = new List<string>();
toolbarItems.Add("Search");
}
<div>
@(@Html.EJS().Grid("Grid").Height(450).EnableVirtualization(true).Toolbar(toolbarItems)
.AllowSorting().AllowFiltering().FilterSettings(filter => { filter.Type(Syncfusion.EJ2.Grids.FilterType.CheckBox); })
.DataSource(dataManager => {dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor");}).Columns(col =>
{
col.Field("CustomerID").HeaderText("EmployeeID").Add();
col.Field("ContactName").HeaderText("OrderID").Add();
col.Field("CompanyName").HeaderText("FirstName").Add();
col.Field("City").Add();
}).Render())
</div> |
|
[Controller]
using EssentialJS2MvcApplication1.Models;
using Syncfusion.EJ2.Base;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace EssentialJS2MvcApplication1.Controllers
{
public class HomeController : Controller
{
NORTHWNDEntities1 db = new NORTHWNDEntities1();
public ActionResult Index()
{
return View();
}
public ActionResult UrlDatasource(DataManagerRequest dm)
{
// here you can apply the data to the Grid
IEnumerable DataSource = db.C30000Records.ToList();
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);
}
int count = DataSource.Cast<C30000Records>().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 }) : Json(DataSource);
}
}
} |