Search code examples
node.jscouchdbcouchdb-nano

How to implement lazy pagination in CouchDB?


I have datatable with many rows, and want to show page numbers + next, previous buttons. Classic Normal pagination. But I only can find docs or information on how to create only Next and Previous buttons functionality, w/o pages. (https://docs.couchdb.org/en/stable/ddocs/views/pagination.html)

CouchDB pagination recipe (basic, or altenate methods) has no examples, and no detailed description, on how to implement page numbers. Only information that allows me to implement next, previous buttons.

For good pagination with pages, I need to know:

  1. Total number of objects (at least)
  2. start_key, end_key for every page

How to get this and Is it possible with CouchDB at all?

The only way I see, is to request all the objects from DB and do pagination on frontend. I guess if you never tried to implement it yourself with CouchDB better not to answer...


Solution

    1. Total number of objects (at least)

    You must have missed that in all the return examples, the total_rows element is still included, so you always have this.

    enter image description here

    1. start_key, end_key for every page

    You're right, if you're using the alternate strategy, as mentioned in the Jump To Page section of the docs, you can't implement the page jump mechanism.