How to create pagination with Meteor Boiler - tutorial
Meteor Boilerplate meteor-boiler purpose is to allow new and experienced developers to start applications quickly. It has borrowed heavily from various meteor resources, books and articles to come up with patterns that can be utilized effectively. The roadmap is @trello to see where it is headed…
This post discusses how to create pagination for large collections. It follows the pattern described in the Discover Meteor book. Extend it as you see fit.
Lets go through a step by step walkthrough in creating pagination for users collection, which could get fairly large.
- Pre-Requisites:
- git clone https://github.com/sunkay/meteor-boiler.git
- mv meteor-boiler Your-Project-Name
- cd Your-Project-Name
- meteor
- in browser go to localhost:3000
- Check if all the tests have successfully passed
Step 1: Create a large set of data
Step 2: Do meteor reset & run meteor to create this data
- cmd-line> meteor reset
- cmd-line> meteor
- cmd-line> meteor mongo
- cmd-line> db.users.find()
- make sure the user data is there…
- Go to http://localhost:3000
- Login as admin user: username: admin@y.com, [admin123]
- Click on Admin - Users link in the sidebar
- It should list all 500 users without pagination
Step 3: Create a route controller [UsersListController]
The route controllers for pagination follow a pattern that can be replicated for other subscriptions.
Step 4: Add the ‘Load More’ block to the template
{{#contentHeader heading="Users" currentPage="Users"}}-
{{#each allusers}}
{{> userItem}}
{{/each}}
{{#if nextPath}}
{{/if}}