Skip to content
v2.7

Pagination

Pages by limit and offset or by cursor, and when to use each.

Every list comes in pages. Without Query.limit, a page has 25 items. The response includes the items and the total number of items that match the filters.

Query.limit(20) and Query.offset(40) return the third page of 20. It is simple and lets you jump to page N, but it gets slower as the offset grows, and items added or removed along the way change what lands on each page.

Query.cursorAfter(id) starts right after item id (the last one on the previous page). It doesn’t slow down at the end of the list and doesn’t repeat or skip items when the table changes. Use it for infinite scroll and to go through everything:

paginacao.ts
// Goes through the whole table, 100 rows at a time
let cursor = null;
do {
const { rows } = await db.listRows({
databaseId: "loja-principal",
tableId: "pedidos",
queries: [
Query.limit(100),
...(cursor ? [Query.cursorAfter(cursor)] : [])
],
total: false // no need to count
});
processar(rows);
cursor = rows.length === 100 ? rows[rows.length - 1].$id : null;
} while (cursor);
Limit and offset Cursor
Jump to page N Yes No
Speed at the end of the list Drops Constant
Repeated items if the table changes Can happen No
Good for Tables with numbered pages Infinite scroll, export

Calculating the total means counting the rows. When the screen doesn’t show the total, pass total: false: the response comes back faster, with total 0.

Was this page helpful?