I want to make pagination with data what is stored in cloud Firestore
. It looks like that:
Note, It is different from load more or infinite loading. Lets assume that, When user click at pager 3, I need to make a request to my Firestore
to get 25 items from position 50 to 75(25 items per page).
I should do like that:
db.collection("cities")
.orderBy("population")
.startAfter(lastVisible)
.limit(25);
The problem here is I do not have lastVisible
. I know we can get lastVisible
by getting first 50 items but it is so dumb because if I do like that, why don't
I just get first 75 items and filter what we want in client.
The question is: How to get a number of items from an index to other index by query in Firestore
?
Any help would be appreciated! Thanks so much!
Updated answer:
You can maintain an array of size as the decided count of your pages. Value at each index would denote the startAt
field value of your cities
field.
Additionally you will also maintain a count of your documents. This will help you give the limit value (count / numberOfPages
).
You will maintain both of these with help of cloud function triggers, as already described here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With