Skip to content

Xerdi/meteor-pager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

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.