alethes / meteor-pages

Meteor pagination
MIT License
403 stars 84 forks source link

Meteor Pages

Out-of-the-box Meteor pagination

Live demos:

Basic usage - http://pages.meteor.com/

Table (using fast-render) - http://pages-table.meteor.com

Reactive, multiple collections - http://pages-multi.meteor.com/

Infinite scrolling - http://pages3.meteor.com/

Live help

Do you need some assistance with Meteor development? I'm happy to help.

Features

Installation

Meteor 0.9+: meteor add alethes:pages

Meteorite: mrt add pages

Basic usage

JavaScript/CoffeeScript (in common code, running on both the server and the client):

this.Pages = new Meteor.Pagination("collection-name");

and HTML:

<body>
    {{> collection-name}}
</body>
<template name="collection-name">
    {{> pages}}
    {{> pagesNav}}  <!--Bottom navigation-->
</template>

Of course, you can use any variable to store the object returned by new Meteor.Pagination(), not necessarily Pages.

As for the customizations, there's a multitude of options. You'll most likely want to define your own template for the paginated items. When you do, you can pass it's name to the Meteor.Pagination constructor:

this.Pages = new Meteor.Pagination("collection-name", {
  itemTemplate: "myItemTemplate"
})

Settings

Settings can be passed as a second argument to Meteor.Pagination(). Many of them can be changed on the client-side, causing an immediate redraw. Unless stated otherwise, user-defined functions are called in the context of the Pagination object.

There are two ways to modify settings:

  1. In common code, during declaration (client and server):
this.Pages = new Meteor.Pagination("collection-name", {
  perPage: 20,
  sort: {
    title: 1
  },
  filters: {
    count: {
      $gt: 10
    }
  },
  availableSettings: {
    perPage: true,
    sort: true
  }
});
  1. Client-side code / common code (client and server), after declaration:
Pages.set({
  perPage: 10,
  sort: {
    title: -1
  }
});

Available to the client anytime:

Unavailable to the client and not changeable on server either after pagination object is initialized:

Examples

Currently, the following examples are available in the /examples directory:

Todos