-
-
Notifications
You must be signed in to change notification settings - Fork 15
Home
Emrah KONDUR edited this page Oct 11, 2021
·
7 revisions
DatatableJS is a helper to create a grid with Jquery Datatables and provides an extension to retrive data generically from Entity Framework context. It possible to use many Jquery Datatables features with Html helper. It gives serverside or client side options.
@(Html.JS().Datatable<Person>()
.Name("PersonGrid")
.Columns(cols =>
{
cols.Field(a => a.Id).Visible(false);
cols.Field(a => a.Name).Title("First Name").Class("text-danger");
cols.Field(a => a.Age).Title("Age").Searchable(false);
cols.Field(a => a.BirthDate).Title("Birth Date").Format("DD-MMM-Y");
cols.Command(a => a.Id, "onClick", text: "Click").Title("");
})
.Filters(filter =>
{
filter.Add(a => a.Id).GreaterThanOrEqual(1);
})
.URL(Url.Action("GetDataResult"), "POST")
.ServerSide(true)
.Render()
)
With .ToDataResult(request)
extension function, data can get with server side pagination very simply.
public JsonResult GetDataResult(DataRequest request)
{
DataResult result = context.People.ToDataResult(request);
return Json(result);
}