DataTables pagination problems

DataTables pagination problems

zakdrizztzakdrizzt Posts: 3Questions: 0Answers: 0
edited May 2011 in General
Hi,
I'm using DataTables server-side processing along with filtering, sorting, row callbacks, hidden columns, etc. The plugin is great and has worked well for the most part so far but I am having some problems getting pagination to work properly.

The first page of the DataTable always works fine with the correct number of displayed rows and the offset starting at 0. Using the pagination buttons below the table is where bad things start to occur.

With a show 10 entries, page 1, I get iDisplayLength = 10 and iDisplayStart = 0. The sInfo says "Showing 1 to 10 of 21 entries".

Loading the 2nd page things change drastically. iDisplayLength = 10 still but iDisplayStart = 010. The sInfo in addition changes to "Showing 0101 to 11 of 11 entries (filtered from 21 total entries)".

After having a look at pretty much every example, usage page, and many forum threads in the process of building this DataTable (and now troubleshooting the pagination) I am at a loss as to what would be causing this odd behavior. I would be happy to pm some of the code I have used if needed. Any insights or relevant threads would be appreciated.

Thanks in advance.

Replies

  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    I believe that you are currently returning iTotalRecords etc from the server as strings rather than integers. If you just return an integer than that should do it.

    Allan
  • zakdrizztzakdrizzt Posts: 3Questions: 0Answers: 0
    Sounded plausible but after going on a casting spree it doesn't seem to have affected a change of behavior. Looks like that isn't an issue (or at least THE issue). It really does seem like it concating the value like strings instead of adding as integers though.

    Any other ideas on where DataTables would be doing something like that?

    If it helps, Firebug shows the XHR Get request sent on the "go to 2nd page of table" request sends through the 010 value for iDisplayStart. Any way that I could be manipulating that incorrectly that early on?

    Cheers for the first thought anyways.
  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    Can you post in your JSON return from the server, as shown in Firebug please?

    Thanks,
    Allan
  • zakdrizztzakdrizzt Posts: 3Questions: 0Answers: 0
    Complete refactor and changing a bit of pagination logic has made the DataTables work perfectly.

    Thanks for the help anyways.

    :)
  • gauravf4ugauravf4u Posts: 4Questions: 0Answers: 0
    Hi zakdrizzt/Alan ,

    I am facing the same issue where in I have a text field where in the user can give the results limit to be displayed in the page.

    1) First time user types 10 in the text field eg results are displayed fine and the sInfo shown properly
    eg
    Showing 1 to 10 of 217 entries
    FirstPrevious12345NextLast

    2)User clicks on the next link and next 10 records are displayed but sInfo changes to below text.
    This is strange as ideally sInfo should be,"showing 10 to 20 of 217 entries".
    Please let me know if you know the solution for this.I am using datatables 1.9

    Showing 0101 to 217 of 217 entries
    FirstPrevious12345NextLast

    Regards
    Gaurav
  • allanallan Posts: 63,530Questions: 1Answers: 10,473 Site admin
    Sounds like your server-side process is returning strings rather than integers for iDisplayRecords etc. If you run your table through the debugger, we can confirm that.

    Allan

    ps. Please don't post your question in multiple threads - it gets very confusing and means sone threads don;t have answers for future users who find the thread by search.
  • neilsneils Posts: 8Questions: 0Answers: 0
    edited November 2012
    I have found a workaround, maybe this is not the proper solution, but works for me:

    Backup your jquery.dataTables.js file. Find these lines starting from line 2938 in jquery.dataTables.js, version 1.9.4:

    [code]
    if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
    {
    oSettings._iDisplayStart += oSettings._iDisplayLength;
    }
    [/code]

    Replace this to:

    [code]
    oSettings._iDisplayStart=parseInt(oSettings._iDisplayStart);
    oSettings._iDisplayLength=parseInt(oSettings._iDisplayLength);
    if ( oSettings._iDisplayStart + oSettings._iDisplayLength < oSettings.fnRecordsDisplay() )
    {

    oSettings._iDisplayStart += parseInt(oSettings._iDisplayLength);
    }
    [/code]

    Tested OK so far...
  • neilsneils Posts: 8Questions: 0Answers: 0
    edited November 2012
    Still there's something to do, the _info div now displays the total records as the display end... sorry for messing up the code. :-)))

    Same file, line 11382:
    Alter this:
    [code]
    return Math.min( this._iDisplayStart+this._iDisplayLength,
    this._iRecordsDisplay );
    [/code]
    To:
    [code]
    return Math.min( this._iDisplayStart+parseInt(this._iDisplayLength),
    this._iRecordsDisplay );
    [/code]
This discussion has been closed.