Server side paging with unknown record count

Server side paging with unknown record count

TimNZTimNZ Posts: 5Questions: 0Answers: 0
edited August 2013 in General
This has been an ongoing discussion for the last couple of years, but I can't find a useful answer.

What are people doing for the scenario where a total record count is infeasible/expensive to calculate?

In this case I want just Prev/Next buttons, and a 'Page X' for info display.

Before I spends hours trying to hack this I'm hoping someone can post their solution.

Replies

  • TimNZTimNZ Posts: 5Questions: 0Answers: 0
    Prev should be disabled for Page 1, and Next should be disabled if num of records returned is < page records e.g. 10
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Currently - there isn't a built in way of doing this. As you say, it has come up a few times but not often enough for me to have included it in the core yet I'm sorry to say (other things demanding attention!).

    There is actually a pull request on this topic which I've yet (I'm ashamed to say since its been outstanding for a while!) to properly review: https://github.com/DataTables/DataTables/pull/60 . It might give you a starting point though.

    I'd be interested to know how you get on with it if you do follow up on it and if it is a fairly light change, then perhaps it is something that I should look at incorporating into 1.10. It should only be the paging and info that really "care" about it - so it might be possible to support view plug-ins only.

    Regards,
    Allan
  • TimNZTimNZ Posts: 5Questions: 0Answers: 0
    Thanks for the pointer Allan, at least I can hack something for the short term.
    I'm sure a few others would also like to see this in core.

    I'm using Mongo DB and it's expensive to do counts - and likely the same with increasing number of NoSQL options.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The only thing I'm concerned about with this is how to know when you get to the end. Lets say you have 100 records in a table and you are showing records 91-100. If you click on 'next' (which would be enabled since there is no ending point), there would need to be something from the server which says "No more rows". DataTables has no concept of handling that at the moment since it knows exactly how many rows there should be.

    Always having 'next' enabled isn't a problem - its just the ending point that I don't know how to handle correctly...

    Allan
  • TimNZTimNZ Posts: 5Questions: 0Answers: 0
    I've already incorporated his changes and it does exactly what I want.

    I incorporated his plugin fnUpdate to a bootstrap themed plugin and made a change to disable Next when the returned record count is < page size, doesn't need to be any more complicated than that.

    I also made a couple more single line changes to prevent (filtered...) being displayed when iTotalRecords is NaN.

    In the case of having 100 records, Next will unfortunately be enabled and return an empty page - not a showstopper.

    You could have the server return { bNoMoreRecords: true } as an option instead of disabling Next if record count < page size.
This discussion has been closed.