kolyasya:meteor-pagination

v0.0.10Published last year

meteor-pagination

Package implements reactive pagination for Meteor apps. It is based on observeChanges callbacks which publish docs into client-side collection like posts.paginated.

Usage example

Check ./example directory for a full working example

Server

Full list of possible params is here — https://github.com/kolyasya/meteor-pagination/blob/main/example/packages/meteor-pagination/server.js#L39

1publishPaginated({
2  enableLogging: false,
3  collection: Posts, // Mongo collection
4  name: 'posts.paginated', // Publication name
5  customCollectionName: 'posts.paginated', // Client-side collection name
6  countsCollectionName: 'posts.paginated.count', // Client-side counts collection name
7});

Client

It is just an example. You need to adjust variables according to your app code.

1export default withTracker(({ perPage, page, sort }) => {
2  const totalRows = Counts.get('posts.paginated.count');
3
4  const paginatedPostsSub = Meteor.subscribe('posts.paginated', {
5    skip: page * perPage,
6    limit: perPage,
7    fields: {
8      title: 1,
9      content: 1,
10    },
11    sort,
12
13    cursorSelector: {},
14  });
15
16  return {
17    postsLoading: !paginatedPostsSub.ready(),
18    posts: PostsPaginated.find().fetch(),
19    totalRows,
20  };
21})(Table);