Pagination for infinite scrolling #1439
-
I'm interested to know how could one implement pagination/infinite scrolling with moor for the following scenario: Backend API would return the following data for each page.
Notice the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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, 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! |
Beta Was this translation helpful? Give feedback.
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 thei
th page. To know how many entries there are in the database, you can usecountAll
: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!