Skip to content

Data retrieval with Paging

Backendless operations returning a collection of objects automatically break up the complete result set into pages. Backendless paging uses two parameters to enable paged data retrieval:

  • page size - identifies how many objects a single page contains
  • offset - identifies the position of the object from which to retrieve the number of records identified by page size

The diagrams below illustrate the paging process. The first diagram shows the first request to retrieve a collection of records. The request includes the parameters of 5 objects in the page, starting from offset 0:

findrequest1

To retrieve the next page of data, the client must set the offset to the index of the first not retrieved object, which is 5:

findrequest2

Important

Backendless server sets the maximum allowed value for the page size to 100 objects. The minimum value is 1.

Flutter applications must use the DataQueryBuilder class to set the paging parameters. The example below configures DataQueryBuilder to load 25 objects starting from offset 50. The query is used to retrieve objects from the Person table:

DataQueryBuilder queryBuilder = DataQueryBuilder()
  ..pageSize = 25
  ..offset = 50;
Backendless.data.of("Person").find(queryBuilder).then((response) {
  // the "response" object is a collection of Map objects.
  // each item in the collection represents an object from the "Person" table
});
DataQueryBuilder queryBuilder = DataQueryBuilder()
  ..pageSize = 25
  ..offset = 50;
Backendless.data.withClass<Person>().find(queryBuilder).then((response) {
  // the "response" object is a collection of Person objects.
  // each item in the collection represents an object from the "Person" table
});

Application can use the same queryBuilder object to recalculate offset (and if necessary change page size) and use it to retrieve additional pages from the server using the same data retrieval method:

// calculate offset to get the next page of data
queryBuilder.prepareNextPage();

// retrieve the next page of data using the same API as for the first page
Backendless.data.of("Person").find(queryBuilder).then((response) {
  // the "response" object is a collection of Map objects.
  // each item in the collection represents an object from the "Person" table
});
// calculate offset to get the next page of data
queryBuilder.prepareNextPage();

// retrieve the next page of data using the same API as for the first page
Backendless.data.withClass<Person>().find(queryBuilder).then((response) {
  // the "response" object is a collection of Person objects.
  // each item in the collection represents an object from the "Person" table
});