Guard
Guard

Reputation: 6955

Meteor client-side pagination

There's a collection Comments. Currently comments for the specfic Content are all published to the client.

Without pagination I can successfully render them in my template, insert new comments and enjoy the reactivity.

I'm fine at the moment with all comments sent to the client but I want to implement all-client-side pagination to visually simplify the page much like FB does.

Hare are the rules:

So effectively it could be like:

I tried to solve this with a bunch of Session variables but didn't succeed -- I think at some point getting and setting these vars from the template leads to recursion or what? Additional problem is that I don't reliably know the 'initial' moment when I should calculate the minTime for the 1st time -- comments may still not be synched when the template is created or rendered for the first time.

So, the question: what is the proper way to fulfill my requirements?

Upvotes: 1

Views: 922

Answers (2)

Dan Dascalescu
Dan Dascalescu

Reputation: 152095

In the meantime there are tow Meteor package for doing client-side pagination, one within a table. I admit I didn't go through all your requirements because of the comment exchange with ram1 above, but the package may help:

https://atmosphere.meteor.com/package/reactive-table

https://github.com/alethes/meteor-pages

Upvotes: 0

ram1
ram1

Reputation: 6470

Solution:

Meteor.startup(function(){
    Session.set('number_of_visible_comments', 5);
});

Template.comments = function() {
    return Comments.find({content: id_of_content}, {
        sort: {timestamp: -1}, 
        limit: Session.get('number_of_visible_comments')
    });
};

Template.total_number_of_comments = function() {
    return Comments.find({content: id_of_content}).count();
};

Template.number_of_visible_comments = function() {
    return Session.get('number_of_visible_comments').count();
};

Template.comments.events({
    'click': function() {
        var count = Session.get('number_of_visible_comments') + 10;
        Session.set('number_of_visible_comments', count);
    }
});

Upvotes: 1

Related Questions