Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DataTables

Dotnet package for binding jQuery Datatables with an ASP.NET back-end.

If you'd like to internalize this library into your project feel free to copy the csharp classes in /src/Datatables to your own projects.

Package: https://www.nuget.org/packages/Wetware.DataTables

Usage

Simply use DataTablesParameters as a parameter in a controller action or page model. ASP.NET will automatically bind what DataTables sends to server.

Controller.cs

[HttpPost]
public IActionResult DataTable(DataTablesParameters parameters)
{
    // Get some stuff from somewhere 

    return Json(new DataTablesReturn<object>{
        Draw = parameters.Draw,
        Data = new List<object>(), // The data to return goes here
        RecordsTotal = 0, // Fill this out
        RecordsFiltered = 0 // Fill this out
    });
}

PageModel.cs

public IActionResult OnPost(DataTablesParameters @params)
{
    var hasSearch = !string.IsNullOrWhiteSpace(@params.Search.Value);

    var people = People
                    .Where(p => !hasSearch || p.Name.Contains(@params.Search.Value))
                    .Skip(@params.Start).Take(@params.Length).ToList();

    return new JsonResult(new DataTablesReturn()
    {
        Draw = @params.Draw,
        Data = people,
        RecordsTotal = People.Count,
        RecordsFiltered = hasSearch ? people.Count : People.Count
    });
}

I recommend using [HttpPost] instead of [HttpGet] since DataTables has a lot of options and depending on your table configuration can overflow the max length for a url.

To see how to wire it up and see it in action see the RazorPagesSample project in the Samples folder.

Reference

For a complete reference on the jQuery Datatables API please use https://datatables.net/reference/api/

About

Dotnet library for binding jQuery Datatables with an ASP.NET back-end

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.