Skip to content

Instantly share code, notes, and snippets.

@mrpeski
Forked from chriswitko/Pagination with Lo-dash
Created July 23, 2022 12:54
Show Gist options
  • Save mrpeski/4ea6c816d69b23b2aa0ccd31b2fb2db9 to your computer and use it in GitHub Desktop.
Save mrpeski/4ea6c816d69b23b2aa0ccd31b2fb2db9 to your computer and use it in GitHub Desktop.
function getPaginatedItems(items, page) {
var page = page || 1,
per_page = 3,
offset = (page - 1) * per_page,
paginatedItems = _.rest(items, offset).slice(0, per_page);
return {
page: page,
per_page: per_page,
total: items.length,
total_pages: Math.ceil(items.length / per_page),
data: paginatedItems
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment