Pagination problem and possible bug

Pagination problem and possible bug

mlittrellmlittrell Posts: 2Questions: 0Answers: 0
edited November 2011 in DataTables 1.8
Hey all,

I've been browsing the forums quite a bit and I can't seem to find a similar problem to mine.

So I'm using a Mongo database to store my data and this causes a problem with iTotalRecords and iTotalDisplayRecords as doing a count the response would be quite expensive. So until I find another way around this I've just been setting those to 1,000,000 and 500,000, respectively. This seems to work fine, however when I click to the next page the bit that originally looked like this:

"Showing 1 to 100 of 500,000 entries (filtered from 999,999 total entries)"

it now looks like this:

"Showing 01,001 to 100,100 of 500,000 entries (filtered from 999,999 total entries)"

Is there any way to fix this? As long as it paginates fine I don't really care, however it's not exactly pretty UX-wise ;)

Also, I looked around the forum quite a bit on a way to get around the need to return an iTotalRecords and iTotalDisplayRecords however I didn't see anything that would help. Has anyone found a way around this?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Make sure you aren't passing strings in where integers are wanted for iDisplayLength

    [code]
    $(document).ready( function() {
    $('#example').dataTable( {
    "iDisplayLength": 50 // instead of "50"
    } );
    } )[/code]

    The reason this can cause issues is because the + operator is overloaded (arithmetic addition for numbers, but concatenation for strings)
  • mlittrellmlittrell Posts: 2Questions: 0Answers: 0
    edited November 2011
    Ah perfect! Yeah I had the iDisplayLength value as a string.

    As far as including iTotalRecords and iTotalDisplayRecords, I decided to just append arbitrary values to the response before DataTables has a chance to process the data. I'll also probably change the counter to say something like:

    "Showing 100 to 200 of a lot of entries."

    This seems to be a decent work around for anyone who's having a similar issue.

    And thank you for your help, it is very much appreciated! :D
This discussion has been closed.