Sorting issue with pagenating in server side processing

Sorting issue with pagenating in server side processing

lip1lip1 Posts: 1Questions: 0Answers: 0
edited April 2014 in DataTables 1.9
Hello there! I am using server side processing with paginating and sorting turned on and managed to get the paging working on a very large data set (>2.4 million rows).

However, I've had problem with sorting. No matter which page I am on, if I click on one of the sort buttons, it will always jump to the first page. Debugging the code revealed that it was caused by the iDisplayStart parameter - it is always set to 0 if the call is originated from the sorting button - thus jumping to page 1. Please help me out!

Another issue I ran into (and solved) was that I need to pass a large number of parameters to the server in the ajax call (for fhServerData). Originally I used $getJSON(...) as the ajax call by following the server side processing example on this site. I found that as the amount of data I pushed into aoData exceeding certain amount, the Datatables grid would just hang there (displaying a Processing... image but doing nothing). After some painful try and error cycles and some googling, it seemed that there is a size limitation somewhere jQuery that prevent Datatables from functioning. I changed the server to accept HTTP POST instead of HTTP GET and replaced $.getJSON(...) to $.post(...) and the problem was gone! The take away from this lesson is - when processing large amount of data (I assume it to be the major reason you wanted to use server side processing in the first place), use POST instead of GET.

Thanks for the help!


  • allanallan Posts: 54,880Questions: 1Answers: 8,601 Site admin
    > if I click on one of the sort buttons, it will always jump to the first page

    This is an intentional feature of DataTables. The reason it does that is that if you click sort on page 5000, then the new data shown on the new page 5000 will have no relevance to the end user - so DataTables drops them back to the start of the dataset which provides context. If you want to change that you would need to make a small change to DataTables (its open source - feel free :-) ).

    Regarding the POST issue, you can use sServerMethod to have DataTables use POST for its built in Ajax options.

This discussion has been closed.