A Bootstrap pager in a Meteor Template.
Add the package to your project:
meteor add xerdi:pager
Here's a minimal example for the pager
template.
The pager takes the page and limit as ReactiveVar
's and takes the record count as Number
via a template helper function.
Template.myPage.onCreated(function () {
this.data.page = new ReactiveVar(0);
this.data.limit = new ReactiveVar(15);
});
Template.myPage.helpers({
records() {
const {page, limit} = Template.instance().data;
return MyCollection.find({}, {skip: limit.get() * page.get(), limit: limit.get()});
},
recordCount() {
return MyCollection.find({}).count();
}
});
The records
helper reuses the page
and limit
to get the actual paged results.
Optionally you can pass a custom array of limits
to the pager
.