Skip to content

Jquery datatable with entity framework using MVC html helper

License

Notifications You must be signed in to change notification settings

amillion/EFDatatable

 
 

Repository files navigation

EFDatatable

Build status NuGet Gitter

What is EFDatatable?

EFDatatable is a helper to create a grid with Jquery Datatable and provides an extension to retrive data generically from Entity Framework context. It possible to use many datatable.js features with Html helper. It gives serverside or client side options. There's more: Wiki Documentation

@(Html.EF().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);
    }

Where can I get it?

Install EFDatatable from the package manager console:

PM> Install-Package EFDatatable

Then add datatables.net Javascript and CSS files or links to your project.

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>

About

Jquery datatable with entity framework using MVC html helper

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • JavaScript 82.8%
  • C# 15.8%
  • HTML 1.3%
  • Other 0.1%