Pagination Bugs

Pagination Bugs

ajaxboyajaxboy Posts: 17Questions: 0Answers: 0
edited April 2012 in DataTables 1.9
The pagination/ ajax pagination is very buggy.

When it prints the numbers at the bottom, the first page might work but then it constantly sends the wrong parameters from the pagination numbers which causes to get the same or wrong data

This is my initial code:
[code]
$(document).ready(function() {
$('#items_list').dataTable( {
"sPaginationType": "full_numbers",
"aaSorting": [[ 0, "desc" ]],
"bProcessing": false,
"bServerSide": true,
"sAjaxSource": "ajax.php?controller=datasource&function=table_page"
} );
} );
[/code]

note that i am using desc order, this might add a little twist

Replies

  • ajaxboyajaxboy Posts: 17Questions: 0Answers: 0
    edited April 2012
    Also it prints more pages/numbers than there are records, there were records for like 2 or 3 pages, and it printed 5 and as you click on page 4 and 5 it creates even more pages ( 6, 7, 8, etc),

    iTotalDisplayRecords solves this issue

    got it work to a point where all pages work 1, 2, 3, 4, etc... but when clicking the pages backward, like from 4, then 3, then 2, etc.. it doesn't work.. and it keeps adding to 'sEcho' even when going backwards
  • ajaxboyajaxboy Posts: 17Questions: 0Answers: 0
    edited April 2012
    so I am guessing sEcho is the page number, but the page number keeps adding up, and doesnt' work backward when going to previous pages
  • allanallan Posts: 61,757Questions: 1Answers: 10,111 Site admin
    > so I am guessing sEcho is the page number

    Its the draw number - http://datatables.net/usage/server-side

    Can you link us to your page please so I can see what might be going wrong (although it would be worth reading through the server-side processing documentation linked above to make sure that your script is returning the expected parameters, given that sEcho currently isn't).

    Allan
  • ajaxboyajaxboy Posts: 17Questions: 0Answers: 0
    I read all the documentation.. I even made use of fnServerParams and fnServerData, and continue to have the same issue.. It would be helpful to pass the page number as well!,

    I now realize that you do not pass a page number, and maybe sEcho is supposed to add up..

    How I am calculating the pagination is by making use of the page number

    $current_offset = $max_count - ($iDisplayLength * ($page_number -1));

    The script is returning all the expected parameters, but does not pass the page number, so I was thinking sEcho was some sort of page number..

    I just started working on this script recently so it is no where near fully functional.. but you can test it .. and see that initially it works sEcho passes the number of pages, and there is no way back to previous pages

    http://99.135.238.187/phpbugs/index.php

    please note that the url above will stop working as soon as I change my ip.
  • allanallan Posts: 61,757Questions: 1Answers: 10,111 Site admin
    The page number would effectively be redundant information since you get the start point (iDisplayStart) and the display length (iDisplayLength) - the page number is a simple calculation away :-). The reason for sEcho is that because Ajax is async, the responses from the server could arrive out of sequence - thus if an old response arrives, DataTables can throw it away if it has already painted a newer request.

    On first load of your page I see the following in the JSON:

    [code]
    "iDisplayStart":"120","iDisplayLength":20,"sEcho":1,"iTotalRecords":36,"iTotalDisplayRecords":36
    [/code]

    That looks okay - iDisplayStart and iDisplayLength have no meaning in the return from the server (as noted in the documentation), so DataTables will ignore them - but that's fine.

    Then I page forward one page and get:

    [code]
    "iDisplayStart":"10","iDisplayLength":20,"sEcho":"2","iTotalRecords":36,"iTotalDisplayRecords":36
    [/code]

    This also looks fine (again ignoring the first two parameters shown):

    And then page back to the first page:

    [code]
    "iDisplayStart":"120","iDisplayLength":20,"sEcho":1,"iTotalRecords":36,"iTotalDisplayRecords":36
    [/code]

    This is going to be ignored because sEcho is a draw count as I mentioned, not a page number From the docs:

    > An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.

    So that looks like the problem to me.

    Allan
  • ajaxboyajaxboy Posts: 17Questions: 0Answers: 0
    edited April 2012
    What is the problem again?... lol sorry I did not catch that.. of so many tries and modifications I've done I made an arbitrary sEcho, but is really regardless with or without it the issue is still there ( I removed it now), and it wasn't actually doing anything, I was just trying different things.

    As for security matters, I am fully aware.. and right now I am just focusing on getting it working locally.. I have not gotten to even the first stage in security so that is really not a concern right now.. I'll get there when I have a more operational system.. (I even removed some security just to make easier to test, for the time being)
  • ajaxboyajaxboy Posts: 17Questions: 0Answers: 0
    oh wait.. is working now it seems :)
  • ajaxboyajaxboy Posts: 17Questions: 0Answers: 0
    Thank you Allan, you are a genius!, I guess my logic was using the page number was due to making up my own logic and not revising anybody's else work :p, you are right the page number wasn't needed, just the number of records served + the length
  • allanallan Posts: 61,757Questions: 1Answers: 10,111 Site admin
    Excellent to hear you got it going - nice one :-)

    Allan
This discussion has been closed.