xerdi:pager

v0.0.3Published last year

Meteor Pager

A Bootstrap pager in a Meteor Template.

Installation

Add the package to your project:

meteor add xerdi:pager

Usage

Here's a minimal example for the pager template.

<!-- Template myPage -->
<div class="card">
    ...
    <div class="card-footer">
        {{> pager page=page recordCount=recordCount limit=limit}}
    </div>
</div>

The pager takes the page and limit as ReactiveVar's and takes the record count as Number via a template helper function.

1Template.myPage.onCreated(function () {
2    this.data.page = new ReactiveVar(0);
3    this.data.limit = new ReactiveVar(15);
4});
5
6Template.myPage.helpers({
7    records() {
8        const {page, limit} = Template.instance().data;
9        return MyCollection.find({}, {skip: limit.get() * page.get(), limit: limit.get()});
10    },
11    recordCount() {
12        return MyCollection.find({}).count();
13    }
14});

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.