Pagination numbering error

Pagination numbering error

cathshadowcathshadow Posts: 20Questions: 0Answers: 0
edited February 2012 in Bug reports
On clicking next/previous, I tend to get Showing 1-15 of 60 results (correctly), on clicking 2, 3, 4 (or next/prev) I get 16-60 of 60 results (however its only showing 15 (correctly)) ... and then 31-60 and then 46 to 60...

the numbers being passed back by the program are ... "iTotalRecords":60,"iTotalDisplayRecords":60 ...

Any thoughts?
«1

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > Any thoughts?

    Yes - the iTotalDisplayRecords return is wrong :-)

    From the documentation of these two parameters ( http://datatables.net/usage/server-side ):

    - iTotalRecords - Total records, before filtering (i.e. the total number of records in the database)
    - iTotalDisplayRecords - Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned in this result set)

    So if your result set only has 15 records in it after filtering, then iTotalDisplayRecords should be 15, not 60.

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    edited February 2012
    Yes, but If I put it as 15 it doesn't allow me to go to the next page. ie. it says "1 to 15 (filtered from 60)"

    and the number is calculated as 15 for the pagination (ie. it only has one page).

    even in the source code for their online ajax examples, they have iTotalDisplayRecords = 57 and iTotalRecords = 57...

    the filtered seems to need to change only when you filter using the search filter box. then I change it to the (x) results..

    (also, page one, which also receives iTotalDisplayRecords as 60 shows correctly 1-15 of 60 its pages 2-4 that have the issue)


    the returned results from the online example:

    {"sEcho":2,"iTotalRecords":"57","iTotalDisplayRecords":"57","aaData":[["Gecko","Mozilla 1.1","Win 95+ \/ OSX.1+","1.1","A"],["Gecko","Mozilla 1.2","Win 95+ \/ OSX.1+","1.2","A"],["Gecko","Mozilla 1.3","Win 95+ \/ OSX.1+","1.3","A"],["Gecko","Mozilla 1.4","Win 95+ \/ OSX.1+","1.4","A"],["Gecko","Mozilla 1.5","Win 95+ \/ OSX.1+","1.5","A"],["Gecko","Mozilla 1.6","Win 95+ \/ OSX.1+","1.6","A"],["Gecko","Mozilla 1.7","Win 98+ \/ OSX.1+","1.7","A"],["Gecko","Mozilla 1.8","Win 98+ \/ OSX.1+","1.8","A"],["Gecko","Seamonkey 1.1","Win 98+ \/ OSX.2+","1.8","A"],["Gecko","Epiphany 2.20","Gnome","1.8","A"]]}
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    [quote]
    Yes, but If I put it as 15 it doesn't allow me to go to the next page. ie. it says "1 to 15 (filtered from 60)"
    and the number is calculated as 15 for the pagination (ie. it only has one page).
    [/quote]

    I don't really understand I'm afraid. The result suggests that your table has been filtered from 60 possible rows down to 15. If it is displaying 15 rows per page, the obviously it shouldn't allow you to see the next page since there are only 15 rows and it is already showing them.

    > even in the source code for their online ajax examples, they have iTotalDisplayRecords = 57 and iTotalRecords = 57...

    Yes - and then as soon as you apply a filter they diverge. As the documentation notes iTotalDisplayRecords and iTotalRecords must be the same when no filter is applied, and different when there is a filter.

    iTotalRecords is the number of records regardless of filtering (in this case from what you say 60)
    iTotalDisplayRecords is the number of records when filtering is taken into account (you say 15 here, so filtering must be applied).

    So the question is, is 60 and 15 your expected result?

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    Yeah thats the thing

    [quote]iTotalRecords is the number of records regardless of filtering (in this case from what you say 60)
    iTotalDisplayRecords is the number of records when filtering is taken into account (you say 15 here, so filtering must be applied).[/quote]

    The results arent actually being filtered. Its just when I click for page 2 i get 16-60 of 60 results (incorrect result count, but correct results)..

    I get the correct entries, just the count at the bottom is wrong . its displaying 15 results (16-30), but saying it's showing 16-60
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Okay - in that case whatever is calculating iTotalRecords is wrong then - it should be resulting in 16 and not 60 as it currently is. So what logic are you using to calculate iTotalRecords?

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    edited February 2012
    iTotalRecords is used using a "select count(*)" on the table,
    iTotalDisplayRecords is used using a "Select count(*) WHERE" (if there's a filter), else it returns the iTotalRecords value

    -> from what I see in your example, iTotalRecords is the TOTAL number of records in the table (returned), and iTotalRecordsDisplay is the same (if you're showing all records (paginated), or different if you've filtered it. if you make iTotalRecords 16, not 60, how can it say next page if a total is less than a filtered total?). also, as in the example above, (datatables own example), both iTotalRecords, and iTotalRecordsDisplay are 57..

    The point here is that 1 - 15(x) (or 2 - 60(x) <--- the problem) of 60 (y)(which is iTotalRecordsDisplay)

    and 1 - x of (eg.12) filtered from 60 (z) which is iTotalRecords the filtered from form of the result

    both are calculating the of (12 filtered from 60) or of (60) correctly.

    the issue here is the automatic calculation of the pagination number is wrong. this is handled by datatables. the issue is at (X) not (Y) or (Z). those numbers are correct
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited February 2012
    > as in the example above, (datatables own example), both iTotalRecords, and iTotalRecordsDisplay are 57..

    Unless you add a filter to the table. If you were to type "Webkit" into the search box, then iTotalRecordsDisplay would be 8.

    I'm afraid that I'm really lost with the x, y and x in your explanation.

    The parameter "iTotalRecords" is simply the number of rows in the table regardless of filtering and paging. In my example that is the table cardinality. "iTotalRecordsDisplay" is simply the number of records that are available in the result set after filtering, regardless of paging (paging has absolutely nothing to do with these two numbers).

    > the issue here is the automatic calculation of the pagination number is wrong. this is handled by data tables

    What pagination number? The page is currently being shown?

    Can you please link me to your page so I can see and understand the problem?

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    The page at the moment isn't live, so that wont be possible yet (it may be live next week though),
    its the current page shown number . so it says the START int (16) to the END int (60) <--- this one is wrong of the TOTAL records from the FILTERED records.

    ie. its showing the correct records for page 2 but telling me its showing 45 records on page 2 where its only showing 15. (it's only supposed to show 15)..
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited February 2012
    What is the exact text that is shown. Is it something like the following?

    Page 1:
    > Showing 1 to 10 of 32 entries (filtered from 58 total entries)

    Page 2:
    > Showing 11 to 20 of 32 entries (filtered from 58 total entries)

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    That's what should be shown.. but it looks more like

    Page 1:

    [quote]Showing 1 to 10 of 32 entries (filtered from 58 total entries)[/quote]


    Page 2:

    [quote]Showing 11 to 32 of 32 entries (filtered from 58 total entries)[/quote]


    Allan
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    How very odd! And what does the JSON reply look like for the second page?

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    {
    "aaData": [
    [
    "2256",
    "user 1008"
    ],
    [
    "2257",
    "user 1009"
    ],
    [
    "1349",
    "user 101"
    ],
    [
    "2258",
    "user 1010"
    ],
    [
    "2259",
    "user 1011"
    ],
    [
    "2260",
    "user 1012"
    ],
    [
    "2261",
    "user 1013"
    ],
    [
    "2262",
    "user 1014"
    ],
    [
    "2263",
    "user 1015"
    ],
    [
    "2264",
    "user 1016"
    ],
    [
    "2265",
    "user 1017"
    ],
    [
    "2266",
    "user 1018"
    ],
    [
    "2267",
    "user 1019"
    ],
    [
    "1350",
    "user 102"
    ],
    [
    "2268",
    "user 1020"
    ]
    ],
    "sEcho": "3",
    "iTotalRecords": 60,
    "iTotalDisplayRecords": 60
    }
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Thanks for posting your JSON. It doesn't match what I would expect from your earlier post about what the information element is showing:

    > Showing 11 to 32 of 32 entries (filtered from 58 total entries)

    There are 15 records in the JSON reply and no filtering applied, so I would have expected it to look something like:

    > Showing 16 to 30 of 60 entries

    I'm afraid I think I would need to see the page in order to see what exactly is happening, since clearly something is amiss!

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    Oh, the earlier post, about the "filtered" was just an example as the problem exists on both.

    You are correct to assume this:

    [quote]Showing 16 to 30 of 60 entries[/quote] should be showing, as this is what I'm expecting,

    However

    this

    [quote]Showing 16 to 60 of 60 entries[/quote]

    is what is actually displayed..

    Also, to note, the problem doesn't happen every time the page is called or visited. sometimes the number is correct, sometimes not..
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    That is very odd indeed - I've not encountered this before I'm afraid, so I'm afraid I don't have an immediate answer. Are you using Scroller or any other plug-ins? Is your JSON reply above from a draw where the problem did show up?

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    No other plugins are being used - this is done with vanilla jquery, and yes this is from one of those cycles... and then later (on the same page the numbers were correct)
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    Thanks for the help though, in the meantime, I've switched the datatables "info" off, and have created my own label.. with "showing (iTotalRows) results" in it < so that my clients dont see an incorrect count :P
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    Here's a screen shot link:
    Incorrect:
    http://www.freeimagehosting.net/rutqo
    Another Anomaly:
    http://www.freeimagehosting.net/3jeue

    And a correct page:

    http://www.freeimagehosting.net/mnj6z
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    Its a difficult issue, since clicking " Next " wont allow you through, as datatables thinks its hit the limit of the result amount.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I've been working on a debugging bookmarklet which might be of some use here. Its still not ready for general release, but I'd be interested if you could try using it on your table when you get this error showing up please: http://debug.datatables.net/

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    Hmm, Been trying the debugger, its been "loading" for the last 20 minutes
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Bummer. That sounds like there might be a JS error. If you look at the Inspector or Firebug console, is there an error reported?

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    Nope, No errors whatsoever
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Double bummer :-(. There is nothing that has been added to the DB, so its not just a timeout thing, something has most certainly gone wrong (I don't fancy the idea of writing a debugger for the debugger!).

    I'm trying to think of what could go wrong and not give an JS error, and failing miserably. If you look at the BODY tag, does it have an iframe attached to it. If so, what is in the content of the body of the iframe?

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    Wait, I reran it...

    illegal character
    http://debug.datatables.net/bookmarklet/DT_Debug.js?rand=1329913526891
    Line 195



    ... && l(e);}, k = !e.bJUI ? \"
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I've just removed that bit from the code - it means that the upload will take a little bit longer since it basically needs to upload DataTables as well (which is obviously fairly pointless, which is why I was removing it), but it should at least get into the DB now to let me see what is going on!

    Thanks for your help with this!

    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    hehe no problem. I tried again (I tried even rebookmarking that link), but have the same error
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    illegal character
    http://debug.datatables.net/bookmarklet/DT_Debug.js?rand=1329913526891
    Line 195
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    That's a bit odd as line 195 is commented out in the file there. I had thought that the random number would stop any cache issues, but possibly not. Could you maybe empty your cache and try one more time? :-)

    Thanks,
    Allan
  • cathshadowcathshadow Posts: 20Questions: 0Answers: 0
    Ok,

    I tried again and same error, then refreshed,and (posted this comment before but it seems to have.. disappeared..)
    this time I got:
    Upload complete - debug code: aledom

    Thats the debug code I got..
This discussion has been closed.