Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set current Page #34

Closed
mladendinev opened this issue Jan 5, 2017 · 1 comment
Closed

Set current Page #34

mladendinev opened this issue Jan 5, 2017 · 1 comment

Comments

@mladendinev
Copy link

I've been trying to set the current page by taking the page number from my url. According to your documentation

documents() {
   var pageNumb = Number(FlowRouter.getQueryParam('page'))
  return Template.instance().pagination.currentPage(pageNumb);
},

should set the page to "pageNumb",but the method currentPage return type is "Int", not object with all docs for this particular page.

@Kurounin
Copy link
Owner

Kurounin commented Jan 5, 2017

That method is not supposed to return the documents, only set the page and return the newly set page number.
If you want to set the page from url, you should set it when initializing, In your template javascript file (e.g. client/scripts/mylist.js):

Template.myList.onCreated(function () {
    this.pagination = new Meteor.Pagination(MyCollection, {
        page: Number(FlowRouter.getQueryParam('page')),
        sort: {
            _id: -1
        }
    });
});

and use the getPage() method to return the documents in a helper:

Template.myList.helpers({
    documents: function () {
        return Template.instance().pagination.getPage();
    }
});

If for some reason (the page is not available when instantiating) you want to set the page after initializing the pagination component you can use:

templateInstance.pagination.currentPage(pageNumb);

but you still need to get the documents in a helper, using the Template.instance().pagination.getPage() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants