Skip to main content

Pagination of Results

For API endpoints that retrieve result lists, the frontend must handle pagination to avoid retrieving the entire result set in a single call, which is limited to a maximum of 100 items. Please note that the Javascript connector, to facilitate the use of these calls, exposes the DiscoveryCms.getContents() method and the corresponding useDiscoveryContents() React hook. In both cases it is possible to pass two fundamental parameters for pagination:

  • start (default 0), which indicates the first content of the list to retrieve, e
  • limit (default 10, max 100) which indicates the number of contents to retrieve with the call.

The returned object, in addition to containing the array with the results (entities), also contains a resultCount property. Please understand that resultCount indicates the total of results for the query, and not the number of results returned (the number of which corresponds to limit).

The resultCount can be used by the frontend to manage pagination to understand if the list of results is finished.

Generally there are two ways to implement pagination on the frontend:

  • endless scrolling
  • display of a pager ([1][2]...)

Which approach to use depends on various UX considerations, there are pros and cons to both approaches. This guide does not go into UX aspects. If you choose to display a paginator, the resultCount is useful for determining the number of pages to display. For example, if you decided to have pages of 25 results (limit = 25) and the resultCount is 100, then the paginator must display 4 pages. The pages will be recovered as follows:

  • page 1: start=0, limit=25
  • page 2: start=25, limit=25
  • page 3: start=50, limit=25
  • page 4: start=75, limit=25

It is good to keep in mind that limit is a maximum limit. If the number of results were 90, the last call would not fail and return 15 results.