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

Problem with currentPage() method to get the current page #72

Closed carlosalvidrez closed 6 years ago

carlosalvidrez commented 6 years ago

Hi there, Wondering if it this is an actual issue or if I'm doing something wrong. As you can see in the code below, I am trying to figure out (when the meteor template is created, after pagination gets instantiated), which page I am at.

I noticed that if I call the currentPage() method, then the pagination stops working (the bootstrap paginator stops responding when I click in other pages). The strange thing is that, if I do not call it (commented below in the code), then it works well.

So, is there a known workaround? Or should I use another method/way to get the actual "current page"?

Thanks

let
    perPage = Template.instance().pagination.perPage()

    //TODO: The paginator stops working if I call this method  :(
    , currentPage = Template.instance().pagination.currentPage()
;

// Start on page 1
Template.instance().pagination.currentPage( 1 );            
Kurounin commented 6 years ago

Hi,

Template.instance().pagination should only be used in helper methods. In event methods you should use the second parameter of the function which gives you access to templateInstance. Since I don't have any context regarding where you used that piece of code, all I can say is that if you used Template.instance().pagination.currentPage( 1 ) inside a helper method the pagination will enter a loop (you shouldn't call setters in helper methods).

carlosalvidrez commented 6 years ago

Thank you... it was an unrelated mistake in my part. I do understand hear/you on not using setters in helpers... thanks for getting back to me, really appreciate it.