ionic-frameworkfirebasefirebase-util

Ionic Firebase Infinite Scroll Order


I can't seem to get my firebase scroll to order properly. I have some posts in Firebase , and i would like to have Firbase order my post from most recent to oldest one. However, it s doing the opposite. The posts are being sorted from oldest to newer.

var ref = new Firebase("https://feburl");
var posts= ref.child('posts');
// create a scrollable reference
var scrollRef = new Firebase.util.Scroll(posts, 'created');

I'm using this : https://github.com/firebase/firebase-util

and an example of usage can be found here: https://gist.github.com/katowulf/7adb5775dce44cbbba0a


Solution

  • One possible solution is to add a timestamp to your data when you store it in Firebase, use Firebase's security and rules to index that data by timestamp and then retrieve the data based on that timestamp.

    In security and rules:

    {
        "rules": {
            "posts": { 
                ".indexOn": "timestamp"
            }   
    }
    

    Then when you are accessing your data:

    var posts= ref.child('posts').orderByChild("timestamp").limitToLast(XX);
    

    Although, I have not tested this with the infinite scroll library.