MUSTAFA ŞAHİN
MUSTAFA ŞAHİN

Reputation: 21

Is it possible to do paging (numbered) with firebase?

I started a project with firebase. Everything was perfect until it came to the paging section. But I was disappointed about paging. Please help me. Now I will write what I want to do.

There are 100 posts. I'll show 25 on each page.so this means 4 pages.When the user wants to move to the fourth page while on the first page, I want the data of the second and third pages not to be downloaded, only the data of the fourth page to be downloaded. one more example. when the user goes to "https://example.com/posts/page-3" I only want the posts on the third page to be fetched.

Is it possible to do this?

Upvotes: 2

Views: 825

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317868

Your question does not specify if you are using Realtime Database or Firestore, but the answer is the same for both of them - it's not possible to do pagination using numeric offsets. In order to request a page of data that starts anywhere after the first item, you are required to know something about that item, or the one that comes right before it. If you don't know anything about that item, you have to start from the beginning, then work you way forward. That's how cursor-based pagination works.

With Firestore pagination, this why the API requires you to pass a DocumentSnapshot to start from, or field values from that document.

Upvotes: 1

Related Questions