Skip to content

Pagination

JSORM supports two types of pagination: offset (traditional) and cursor (keyset).

Only works within .get() with pagination in the options:

const { data: users, meta } = await jsorm.users.get({
select: { id: true, name: true },
pagination: { page: 1, perPage: 10 },
});
meta.page; // current page
meta.perPage; // records per page
meta.total; // total records
meta.lastPage; // last page

Uses .cursor() with required orderBy:

const { data: users, meta } = await jsorm.users.cursor({
select: { id: true, name: true },
orderBy: { id: "asc" },
limit: 20,
});
meta.cursor.hasNext; // true if there are more records
meta.cursor.next; // cursor for next page
meta.cursor.previous; // cursor for previous page
// First page
const { data: users, meta } = await jsorm.users.cursor({
orderBy: { id: "asc" },
limit: 20,
});
// Next page
if (meta.cursor.hasNext) {
const { data: nextUsers } = await jsorm.users.cursor({
orderBy: { id: "asc" },
limit: 20,
after: meta.cursor.next,
});
}

Type When to use
Offset UI with traditional pagination (page buttons)
Cursor APIs with infinite scroll, feeds, long lists