Pagination not displaying correctly using Server Processing

Pagination not displaying correctly using Server Processing

kungfuafricankungfuafrican Posts: 4Questions: 0Answers: 0
edited January 2011 in General
I'm displaying images in a datatable using server-side processing. My php script is returning json data correctly with no errors and the images are displaying correctly. However, the pagination only displays page 1, regardless of the total number of records. Here is the json data my script is returning:

[code]
{"sEcho": 1, "iTotalRecords": 8, "iTotalDisplayRecords": 3, "aaData": [ ["20110104114559_0803970_100x100.jpg","20110104114557_7799150_100x100.jpg","20110104114558_2098830_100x100.jpg","20110104114558_6424400_100x100.jpg","20101216113555_8909480_1_100x100.jpg"],["20101216113551_7584950_1_100x100.jpg","20101216113549_8469960_1_100x100.jpg","20101216104842_1_100x100.jpg","20101216104826_1_100x100.jpg","20101216113543_3061300_1_100x100.jpg"],["20101216113547_9734920_1_100x100.jpg","20101216104820_1_100x100.jpg","20101216104816_1_100x100.jpg","20101216104808_1_100x100.jpg","20101216104813_1_100x100.jpg"]] }
[/code]

Sorry if this is difficult to read, but the relevant info is really just in the first line. The aaData seems to be formatted correctly since it is returning no json errors and the images are displaying. What I don't understand is, if iTotalRecords is 8 and iTotalDisplayRecords is 3, why does the pagination not display buttons for page 2, 3, etc.. ?

Here's another weird thing, if I set iDisplayStart to display page 2 initially, then the pagination buttons for page 1 & 2 will appear and the records that should be displaying on page 2 will display. However, as soon as I click back to page 1, the records for page 1 correctly display, but the page 2 button disappears!

Replies

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin
    I think you might have slightly misunderstood the two parameters:

    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)

    From: http://datatables.net/usage/server-side

    So iTotalDisplayRecords is the total number of rows in a table after filtering (not just on the current page) and iTotalRecords is the total number of rows without any filtering.

    Allan
  • kungfuafricankungfuafrican Posts: 4Questions: 0Answers: 0
    Thank you Allan for the extremely fast response.

    Here's a question then, hopefully I word it correctly. If iTotalRecords doesn't report the total number of filtered hits, and the server-side script supplies, with aaData, a number of results based only on iDisplayLength rather than all filtered hits, how does the datatables js script know how many total pages to apply to the pagination? Is it deriving everything it needs just from the returned json data?
  • kungfuafricankungfuafrican Posts: 4Questions: 0Answers: 0
    Actually nevermind I responded too quickly. Thank you for your help.
This discussion has been closed.