Large REST request paging

Afternoon LEAF,

I have a mongo collection with 20k documents in it that I want to make available in an ag-grid table. Does LEAF provide a paged query that I could use to avoid requesting the entire 20k documents in a single REST request?

I would like to load the data incrementally, behind the scenes so as to not interfere with the user experience.

Thanks guys.
sg

Hey there!

LEAF’s DataObjectQuery does include what it calls a PagingSpec, which can be used to specify which page you want to load for a specified number of objects per page.

When using the DataObjectTable UI component, the PagingSpec on the query you provide to the table is honored.

This page on the docs site shows how to include PagingSpecs on DataObjectQueries in Java/JS/TS, but it’s a similar pattern for Python and C# as well. One thing to keep in mind is the first page is 0 (not 1). So to load the 3rd page of 20 objects per page using JavaScript, you would specify the PagingSpec like this:

import { DataObjectQueries as Q } from '@leaf-framework/core';
...

const query = Q.dataObjectQuery({
  pagingSpec: { pageSize: 20, pageNumber: 2 },
  sortingSpec: {
    directives: [{ propName: 'firstName' }],
  },
}).addFilters(Q.types('Person'), Q.geoWithin('coords', polygon));

Not a JS guru, so someone on @javascript can correct me if I’m missing anything!

1 Like