I'm trying to realize pagination with Firestore with filtering + ordering on the frontend but page items must be loaded after click on needed page instead of loading all data and paginating it in browser.
The one option to paginate data in Firestore is cursors where I need to know concrete element (DocumentSnapshot.data()
) to request startAfter/startAt/endAt/endBefore to load next page OR the field values to start this query at, in order of the query's order by.
- What if I need to load the 3rd page of 10?
- How could I know what pages are there without fetching all items?
- And the main question - on what element I should paginate with
startAfter
?
Now my code works with such algorithm: on every change filter/order I fetch ALL users from Firestore such as on initial fetch and calculate what element I should use in startAfter
when loading any of pages. Well, this method works, but it defeats the purpose of pagination. It is very bad practice, but workable.
P.S. there is a method offset
in cloud-firestore backend library but on the frontend library it is absent. And there is an issue on github says it couldn't be realized on front. one