Created
January 21, 2016 02:51
-
-
Save themeteorchef/af54bae2979c06e47267 to your computer and use it in GitHub Desktop.
Revisions
-
themeteorchef created this gist
Jan 21, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ 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 hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ // API: pagination subscription, collection to paginate's global var, number of items per page, current page. Meteor.subscribe( 'pagination', 'CollectionGlobalVar', 10, this.params.page );