Full_numbers pagination Next Button/iDisplayStart problem

Full_numbers pagination Next Button/iDisplayStart problem

DFDF Posts: 13Questions: 0Answers: 0
edited June 2011 in General
I am using 1.7.6 and have a datatable with serverside processing:

[code]

iTable = $('#search-item-tbl').dataTable({
"bJQueryUI": true,
"bAutoWidth": false,
"bLengthChange": false,
"bPaginate": true,
"sPaginationType": "full_numbers",
"sScrollY": "406px",
"bFilter": false,
"bProcessing": false,
"iDisplayLength": "20",
"bServerSide": true,
"bSort": false,
"sAjaxSource": "http://myserver.com/serve_it.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
},
"oLanguage": {
"sSearch": "Filter:",
"sEmptyTable": "There are no active search results",
"sInfo": "_START_ to _END_ of _TOTAL_"
},
"aoColumns":[
{"sWidth": "50%", "bSortable": false}
]
});
[/code]

When I initially run a query which returns 35 results, the following parameters are being passed to the server:

[code]
iDisplayLength 20
iDisplayStart 0
[/code]

Everything comes up properly: info reads "1 to 20 of 35" and I get First, Previous, 1, 2, Next and Last pagination buttons.

Now for the weird part. If I click on the 2 or Last buttons, the iDisplayStart passed to the server is "20" and the info displayed, after my server returns its data, properly reads "21 to 35 of 35". BUT, if I click on the Next button, the iDisplayStart passed to the server is "020" and, following return of data from my server, the info is incorrectly displayed as "0201 to 35 of 35". (In all cases, the correct rows are displayed in the table.)

Is there a fix for this?

Thanks.

-Doug Forrest

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    The numbers you are passing back for iTotalRecords and iTotalDisplayRecords are strings and not integers as DataTables requires (hence the string concatenation rather than numeric addition) - see http://datatables.net/usage/server-side for more information.

    Allan
  • DFDF Posts: 13Questions: 0Answers: 0
    Thanks, Allan, for the answer (it fixed it) and the promptness of your reply.

    On the server, I was setting iTotalRecords and iTotalDisplayRecords directly from the numFound value returned in a json response from a solr/lucene query and didn't realize that it was being assigned as a string instead of an integer in my code.

    datatables continues to be top of the class for jQuery grids!

    -Doug Forrest
  • severinseverin Posts: 11Questions: 0Answers: 0
    Hi,

    i'm running into the same Problem, but i can't figure out how to tell my script to return iTotalRecords and iTotalDisplayRecords as integers. My Data is returned as follows:
    [code]
    {
    "aaData":[
    [
    "\u003Ctable\u003E\n\t\u003Ctr\u003E\n\t\t\u003Ctd\u003E\n\t\t\t\u003Cimg src=\u0022.\/images\/plus.jpg\u0022 class=\u0022show_konlistdet\u0022\u003E\u003Cimg src=\u0022.\/images\/minus.jpg\u0022 class=\u0022hide_konlistdet\u0022 style=\u0022display:none\u0022\u003E\u0026nbsp;\u003Ca href=\u0022.\/index.php?action=kon_details\u0026KON_ID=3\u0022\u003Ekein Name\n\t\t\u003C\/td\u003E\n\t\u003C\/tr\u003E\n\t\u003Ctr style=\u0022display:none;\u0022\u003E\n\t\t\u003Ctd\u003E\n\u003Cspan class=\u0022listdet\u0022\u003EEs wurden keine aktiven Firmenzuordnungen gefunden.\u003C\/span\u003E\n\t\t\u003C\/td\u003E\n\t\u003C\/tr\u003E\n\u003C\/table\u003E\n"
    ,""
    ,""
    ,""
    ]
    ]
    ,"iTotalRecords":12129
    ,"iTotalDisplayRecords":12129
    ,"sEcho":1
    }[/code]

    what would i have to change for it to work properly?
    thanks in advance!
  • severinseverin Posts: 11Questions: 0Answers: 0
    I finally figured it out. The problem was not with iTotalRecords or iTotalDisplayRecords, but with the initial iDisplayLength - setting. those were strings and thus created the strange behaviour.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    I've made a note to add a parseInt into DataTables for those parameters (will be in the next release) as this little "gotcha" crops up every now and then. Thanks for following up on your post.

    Allan
This discussion has been closed.