whoami
whoami2y ago

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
Indy
Indy2y ago
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.
Indy
Indy2y ago
First would like to understand why that doesn't fit your needs so we can improve the api.
Indy
Indy2y ago
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
Indy
Indy2y ago
Hopefully that helps
whoami
whoamiOP2y ago
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
ballingt
ballingt2y ago
@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.
ian
ian2y ago
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.

Did you find this page helpful?