Back

Get pagination end

  • 1
  • Databases
  • Flutter
D5
28 Apr, 2023, 11:28

Is there any way to know if the pagination has ended? (Or if it's the last "page") When making an infinite scrolling pagination, It's needed to know if the end was reached to stop making requests and loader

TL;DR
The user is asking for help on how to determine the end of pagination. They are currently using offset pagination and want to know if there is a way to know when they have reached the last page. The solution provided is to start with a limit of 100 and an offset of 0. If the server returns a full page of results (100 items), increase the offset by 1 and make another request until the server returns fewer results than the limit allows. Using this method, they will know they have reached the end of pagination.
joeyouss
28 Apr, 2023, 11:34

Hi, are you using cursor or offset pagination right now?

D5
28 Apr, 2023, 11:42

@joeyouss Offset pagination

D5
28 Apr, 2023, 11:43

I could use cursor if needed to achieve that

joeyouss
28 Apr, 2023, 11:52

So, start with a limit of 100 since that is the maximum and and an offset of 0 (the first page).

If the server returns a full page of results (eg, 100 items in this case), then increase the offset by 1 and make another request -> because there are more documents.

Continue doing this until the server returns fewer results than the limit allows (100).

this way, you know you have reached the end

joeyouss
28 Apr, 2023, 11:52

Does this make sense?

joeyouss
28 Apr, 2023, 11:53

you just need to see the time when less than 100 items are returned since that will be the last

D5
28 Apr, 2023, 12:00

Ok, that's what I was doing, but as I see, there's not another way to achieve the same

D5
28 Apr, 2023, 12:00

Thanks

joeyouss
28 Apr, 2023, 12:01

let me just quickly confirm if there is another way too

D5
28 Apr, 2023, 12:01

Also I don't understand why I get 23 elements when having 21

D5
28 Apr, 2023, 12:01

Ok, thanks

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more