Limit & Offset Pagination
Hi team, I am wondering if there is a
{take: number, skip: number}
(basically the number of elements per page, and the start index where the query starts like here https://www.howtographql.com/typescript-helix/10-filtering-pagination-and-sorting/) API for handling the pagination without cursor? If not, what is the best way for me hack into this? Thanks!7 Replies
Hi @whoami I am assuming you've already looked at this: https://docs.convex.dev/database/pagination and didn't find it satisfactory for your needs.
Paginated Queries | Convex Developer Hub
Load paginated queries.
First would like to understand why that doesn't fit your needs so we can improve the api.
Second, if you really did want to do something like limit / skip queries. I believe the best way would be to create an index on a monotonically increasing number column you maintain yourself. https://docs.convex.dev/database/indexes/
We don't have support for built in autoincrement so you'd have to find a way to keep track of the max number yourself (probably by looking at the largest number before inserting in a
mutation
).Indexes | Convex Developer Hub
Indexes are a data structure that allow you to speed up your
Hopefully that helps
yea I saw that documentation and my scenario was not a infinite scroll, instead it is just a simple table with multiple pages where you can set the rows per page and choose the pages you want
@whoami there are several options here, are the things you're paging over changing quickly? How many are there? If there aren't hundreds of pages, the infinite scroll-oriented hook could work well for a table too.
This is a great q, and I imagine others are going to want to see some options, so I'm going to duplicate some of this in the #support-community channel and give some options there.