Tuesday, November 5, 2013

Server side paging, filtering and sorting using datatables


Nothing better than writing some code to explain a feature. This post shows how to do server-side paging in a table using datatables.net
The idea is to display a table with a large amount of data (68k rows). As it's not a good practice to load all at once, it' better to implement server-side paging.

First download datatables.net from here and reference them in your html file.

In our sample we are using a table Tasks with 3 fields, ie, TaskID, TaskName, Complete

Lets create the HTML markup first



Now lets wire up datatable to the table



Here as you can see TaskID and TaskName are sortable and searchable.
Now, the model that is passed from datatables to server-side



Finally, the controller method


That's all to it. Happy coding!

Related Posts :



4 comments on "Server side paging, filtering and sorting using datatables"

Add your comment. Please don't spam!
Subscribe in a Reader
Georges DAMIEN on December 22, 2014 at 1:34 PM said...

Good article ! thanks !

Sourav Mondal on December 5, 2015 at 1:17 AM said...

http://www.dotnetawesome.com/2015/11/implement-jquery-datatable-in-aspnet-mvc.html

Here we will see followings with ASP.NET MVC as server side...
Part 1: Implement jQuery Datatable (Basic initialization) in ASP.NET MVC application.
Part 2: jQuery Datatable server side pagination and sorting in ASP.NET MVC
Part 3: Implement custom multicolumn server-side filtering in jQuery dataTables

Unknown on December 7, 2015 at 8:59 PM said...

I was trying to find the way to do server-side pagination. The example in datatable.net did not work for me . Your solution is perfectly working . Thank you very much. If you would be in Istanbul , I could buy you a drink :) Thanks a lot !

Unknown on December 7, 2015 at 9:03 PM said...

I was trying to find the way to do server-side pagination. The example in datatable.net did not work for me . Your solution is perfectly working . Thank you very much. If you would be in Istanbul , I could buy you a drink :) Thanks a lot !

Post a Comment