Return to page one upon sorting

Return to page one upon sorting

filipe.mateusfilipe.mateus Posts: 2Questions: 0Answers: 0
edited March 2009 in General
I have a table paginated on 5 pages. For instance, If I'm on page 3 and click on column header to do a sort, the current page is still 3 but I'd like to return to the first page every time the sort changes.

Strangely, the demo at http://www.datatables.net/examples/example_events_post_init.html works like this but I can't understand why the other demo http://datatables.net/ stays on the current page when sort changes.

Replies

  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Hi Filipe,

    This one had me a little confused for a minute or two! It turns out that the demo at http://datatables.net was actually using an old version of DataTables (1.4 beta 7) which ha this bug in it. The new versions don't exhibit this problem, as you pointed out with the example link.

    If you download 1.4.3 (or 1.5 beta x) then the feature you are looking for should work great.

    Regards,
    Allan
  • filipe.mateusfilipe.mateus Posts: 2Questions: 0Answers: 0
    The bug still exists in 1.4.3. I noticed the problem occurs only when { "bFilter" : false } is passed to dataTable function. Otherwise, the current page is actually reset to first page upon sorting.
  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Hi Filipe,

    Thanks for narrowing this down to bFilter! You are quite right, there is a difference in the sort handling between the filtering feature and the non-filtering feature. THis is caused by filtering resetting the page display back to the first page, but the sorting doesn't explicitly to this. I think it probably should. I've fixed this in my latest copy of 1.5 and will be released in the next beta.

    If you want to fix this in 1.4.3, you can insert the following code just after line 2586:

    [code]
    oSettings._iDisplayStart = 0; /* reset display back to page 0 */
    [/code]

    Regards,
    Allan
This discussion has been closed.