Skip to content

Pagination for infinite scrolling #1439

Answered by simolus3
sharoonamjid asked this question in Q&A
Discussion options

You must be logged in to vote

Your general approach of loading pages from the database and the backend sounds reasonable to me.

You can use limit to implement pagination on queries. Basically, limit(pageSize, offset: pageSize * i) load's the ith page. To know how many entries there are in the database, you can use countAll:

final amountExpr = countAll();
final query = selectOnly(yourTable)..addColumns([amountExpr]);

return query.map((row) => row.read(amountExpr)).getSingle();

Then, divide the amount of rows by the page size and round up to know how many pages there are in the database. I hope that helps!

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sharoonamjid
Comment options

Answer selected by sharoonamjid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants