Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
How do I paginate my posts from firestore to my Javascript web app. Am not using any framework except Node.js server

Below is the code I have tried.Am really new to programming

var records_per_page = 4;
  
  var first = firebase.firestore().collection("Posts").limit(records_per_page);

  first.get().then((snapshot)=>
    {
        document.getElementById("post-container").innerHTML = '';
        snapshot.forEach(function (taskValue) {
            if(snapshot.size >= 1){
                showPosts(taskValue)
                 
                    $("#next").click(function(){
                        var lastVisible = "";
                        lastVisible = snapshot.docs[snapshot.docs.length-1];
                        showMorePosts(records_per_page,lastVisible)
                    })
             
            }
           
        });
        
    }
  );

But the code fetches the first and second four documents only. I have created a gist here to show both methods showMorePosts(records_per_page,lastVisible) and showPosts(records_per_page). Stackoverflow doesn't allow me to add a lot of code.

This is how my database looks like

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

There are two ways to do this, one is by using the offset and other is by using the functions startsAfter() and limit().

You can use offset function to fetch the documents, but it is generally not a great option, because when you call this offset method in the server libraries, you still get billed for builds that you’re offsetting.

So, generally it is better to use startsAfter() and limit(), because those will only get billed for the actual work you’ve performed and none of the one you skipped.

Also you can try following this tutorial on Firestore Pagination for the beginners.

about 4 years ago · Juan Pablo Isaza Report

0

I managed to create some sort of pagination so that when a person clicks next button, the next set of four posts replaces the former, continuously. However, am still figuring out on how to implement the previous button functionality so a person can load the previous sets of posts without having to refresh the page. I created a gist here. You can check it out for further progress and advise.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!