Skip to content

Instantly share code, notes, and snippets.

@themeteorchef
Created January 21, 2016 02:51
Show Gist options
  • Save themeteorchef/af54bae2979c06e47267 to your computer and use it in GitHub Desktop.
Save themeteorchef/af54bae2979c06e47267 to your computer and use it in GitHub Desktop.
Pagination Experiment
Meteor.publish( 'pagination', function( collection, split, page ) {
check( collection, String );
check( split, Number );
check( page, Match.OneOf( String, Number ) );
var documents = global[ collection ].find( {}, { fields: { _id: 1 } } ).fetch(),
documentChunks = _.chunk( documents, split ),
filter = page ? parseInt( page, 10 ) : 0,
ids = _.map( documentChunks[ filter ], '_id' );
return global[ collection ].find( { _id: { $in: ids } } );
});
// API: pagination subscription, collection to paginate's global var, number of items per page, current page.
Meteor.subscribe( 'pagination', 'CollectionGlobalVar', 10, this.params.page );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment