Created
January 21, 2016 02:51
-
-
Save themeteorchef/af54bae2979c06e47267 to your computer and use it in GitHub Desktop.
Pagination Experiment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } } ); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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