noob saibot
noob saibot5mo ago

How to explicitly set the current page in a nextjs paginated query?

In my nextjs application, I have a use case where user can "jump" to a specific page and not only progress sequentially. For that user can indicate this url parameter ?page=n. How can I apply this parameter in my paginated query? In other words, I have created my paginated query function:
export default query({
args: {
paginatedOpts: paginationOptsValidator,
},
handler: async (ctx) => {
...
}
});
export default query({
args: {
paginatedOpts: paginationOptsValidator,
},
handler: async (ctx) => {
...
}
});
The paginationOptsValidator object defines a cursor property. Is this the property I should use? If yes, how should I proceed? Thanks
1 Reply
ian
ian5mo ago
Generally Convex works better with infinite-scroll type pagination right now, where you'd fetch from some starting point and fetch subsequent pages to skip ahead. You can pre-compute cursors and store them in a table of pages if you want to be able to jump to them directly (and the order doesn't change often) Some resources: https://docs.convex.dev/database/pagination https://stack.convex.dev/pagination https://search.convex.dev/?q=pagination
Take Control of Pagination
Convex offers robust control over pagination with a powerful function, getPage, enabling complex edge cases. In this article, we go over how to use th...
Convex Developer Search
Search Docs, Stack, Discord all at once

Did you find this page helpful?