Kurounin / Pagination

This package allows you to paginate the subscriptions over meteor's collections. It can be used in a Blaze template or in ReactJS.
MIT License
56 stars 22 forks source link

How to use this pagination reactively? #55

Closed group22dsl closed 7 years ago

group22dsl commented 7 years ago

this.pagination = new Meteor.Pagination(Customers, { sort: { name: 1 } }); Original code is like above. But I think this subscription is not reactive. I want to change this sorting like following.

this.pagination = new Meteor.Pagination(Customers, { sort: { name: Session.get("sortNumber") } });

But it not works with Session. Please help me to solve this. Thanks

Kurounin commented 7 years ago

If you're using Blaze template, then you can do it like this:

Template.myList.onCreated(function () {
    this.pagination = new Meteor.Pagination(Customer, {
        sort: {
            name: 1 // set initial sort
        }
    });

    this.autorun(() => {
        // change sorting every time the session value for sortNumber changes
        this.pagination.sort({ name: Session.get("sortNumber") });
    });
});