Skip to content

Instantly share code, notes, and snippets.

@michaelNgiri
Forked from jstott/paginated.js
Created January 16, 2020 20:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelNgiri/0cfa73bfec0a759db5cac4c00a5bbf36 to your computer and use it in GitHub Desktop.
Save michaelNgiri/0cfa73bfec0a759db5cac4c00a5bbf36 to your computer and use it in GitHub Desktop.
lodash paginated items
function getPaginatedItems(items, page, pageSize) {
var pg = page || 1,
pgSize = pageSize || 100,
offset = (pg - 1) * pgSize,
pagedItems = _.drop(items, offset).slice(0, pgSize);
return {
page: pg,
pageSize: pgSize,
total: items.length,
total_pages: Math.ceil(items.length / pgSize),
data: pagedItems
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment