
Does anyone have a properly implemented example code for pagination ? I am thinking of using the cursorAfter and cursorBefore to lazily load the feed data but would be great to get some good examples on how to go about it.

Hi, while I search for examples, gonna leave this here for reference: https://dev.to/appwrite/this-is-why-you-should-use-cursor-pagination-4nh5

Example of cursor pagination loading all pages: https://github.com/Meldiron/almost-gist/blob/main/backend/functions/onGistChange/src/index.js#L116-L143

I'll check it out. Thanks Jyoti

@joeyouss Shouldn't this example return all the documents ?
return [
...response.documents,
...(await getAllPages(collectionId, queries, nextCursor))
]
}
The await function will keep executing till it finds all the documents. How would it be different than listing the entire collection at once ?

That's a recursive function that calls itself until it fetches all pages so there are multiple API calls to get all the data

True but from what i understand, it will recursively call till it fetches all the documents from the collection right and finally returns an entire array of it ? This does not look not like it is being lazily loaded for infinitely scrolling a feed.

No it is not, but perhaps it shows you how to use the cursor

The rest depends on your front end. You would make another list documents API call when you're towards the end of your list

thanks for clarifying, the api documentation covers the cursor usage well. I was just wondering how we would actually implement it in a flutter app. If i wanted to fetch all documents, i would just listDocuments the entire collection though.

Maybe this will help: https://pub.dev/packages/infinite_scroll_pagination

I'm pretty sure I've also seen tutorials online for how to implement infinite scrolling.

The general idea is all the same..once the user reaches the end or as they get close to the end, fetch more data

This sounds interesting. I'll check it out, thanks !
Recommended threads
- "Memberships privacy" setting in 1.7.4
Hi everyone, I'm experiencing an issue with a clean self-hosted installation of Appwrite version 1.7.4. I previously used version 1.6.1, and if I remember corre...
- Function 404 error - Deployment with the...
I have a function in my Appwrite Cloud (free plan) project that cannot be accessed or deleted (404 in both UI and CLI). I'm stuck at the 5 functions limit and c...
- 1.6 to 1.7 does not work
Appwrite (self-hosted) stopped working after updating from 1.6.2 that was stable. Getting the general_server_error. Mentioning I fallowed all steps for upgrad...
