项目作者: Navybits

项目描述 :
Simple pagination package cooked for use in meteor apps
高级语言: JavaScript
项目地址: git://github.com/Navybits/meteor-pagination.git
创建时间: 2017-01-03T08:06:25Z
项目社区:https://github.com/Navybits/meteor-pagination

开源协议:

下载


navybits:pagination


Unmaintained Repository

Nobody is maintaining this repository currently.
Use it at your own risk.

Description

navybits:pagination is a simple pagination package cooked for use in meteor apps.
This package provides two major advantages upon other pagination packages:

  1. Server independency: It does not include code that need to be run on server side. It’s your data, and you know what data you want to paginate!
  2. Flexibility: The package is flexible by mentality, it supports each kind of the following situations :
    • Pagination of a set of documents from existing data collection through subscription. A good example is the pagination of all feedbacks (data collection) sent by users in an efficient way (Think about 10,000 feedbacks during 2 years of service) .
    • Pagination of an array field in all documents in a collection. For example pagination of all comments(array field) for all posts (collection) (Think about 100 comments for each of 10,000 posts in your system, imagine these comments are distributed upon 5 years of service).
    • Pagination of a set of data that exists on client side. This happens in case you already have a set of data and you want to enhance the user experience.

Dependencies

Installation:

  1. meteor add navybits:pagination

Use

Usage with blaze:

For instance, we will cover the 3rd use case of data pagination where you already have your data and you want to enhance the user experience:
in your temp.js file

  1. //We will use a helper
  2. //which is handling the data
  3. //to be paginated
  4. Template.temp.helpers({
  5. dataToPaginate:function(){
  6. //return your data as an array of objects
  7. return [{name:"taha",age:25},{name:"Mohammad",age:31}];
  8. }
  9. });

Then in your temp.html file

  1. {{#navybitsPagination data=dataToPaginate}}
  2. <div>Name : {{name}} , age :{{age}}</div><br/>
  3. {{/navybitsPagination}}

Congratulations! This way you will have the 2 array elements paginated. Pretty cool not ?!
This is just a demo, obviously you have to fill the dataToPaginate helper by you own data set

Usage with React:

When using React, it is possible to render blaze templates:
First, let’s say you have the following blaze template pagination.html:

  1. <template name="pagination">
  2. <table>
  3. <thead>
  4. <tr>
  5. <th>Name</th>
  6. <th>Age</th>
  7. </tr>
  8. </thead>
  9. {{#navybitsPagination data=dataToPaginate isTable=true}}
  10. <tr>
  11. <td>{{name}}</td>
  12. <td>{{age}}</td>
  13. </tr>
  14. {{/navybitsPagination}}
  15. </table>
  16. </template>

Now you have the blaze template using navybits:pagination ready, all you need is a way to let React renders this template. For this purpose, you can use gadicc:blaze-react-component package:
Let’s create a wrapper component for your pagination template, for example paginationBlazeWrapper.js:

  1. import React, { Component } from 'react';
  2. import Blaze from 'meteor/gadicc:blaze-react-component';
  3. export default class NavybitsPagination extends Component {
  4. render() {
  5. return <div>
  6. <Blaze template="pagination"
  7. dataToPaginate={this.props.data}
  8. ></Blaze>
  9. </div>
  10. }
  11. }

That’s is, now you have your NavybitsPagination component ready to reuse as much as needed, let’s say in some other component:

  1. import NavybitsPagination from './paginationBlazeWrapper';//choose the right path for your file 'paginationBlazeWrapper.js'
  2. ....
  3. ....
  4. ....
  5. render(){
  6. return (
  7. ...
  8. <NavybitsPagination
  9. data={[{name:"taha",age:25},{name:"Mohammad",age:31}]}
  10. ></NavybitsPagination>
  11. ....
  12. )

Congratulations! That’s it

For more details about using the package in different situations, please visit our blog post page :
Visit our blog

Version

1.0.0

License

MIT