Skip to content

Instantly share code, notes, and snippets.

@peterkarn
Created October 24, 2022 14:22
Show Gist options
  • Save peterkarn/b241f470c0b2b7196dff6dc3f3a8a57d to your computer and use it in GitHub Desktop.
Save peterkarn/b241f470c0b2b7196dff6dc3f3a8a57d to your computer and use it in GitHub Desktop.
calculateItems() {
let currentPage = 3; //needs to be get dynamically
let itemsTotal = 25;
const maxItemsPerPage = 12;
const lastPage = Math.trunc(itemsTotal / maxItemsPerPage) + 1;
let shownFrom, shownTo;
if(currentPage === 1) {
shownFrom = '1' ;
shownTo = maxItemsPerPage;
} else if (currentPage === lastPage) {
shownFrom = itemsTotal;
shownTo = itemsTotal;
} else {
shownFrom = (currentPage - 1) * maxItemsPerPage;
shownTo = currentPage * maxItemsPerPage;
}
return {
shownFrom, shownTo, itemsTotal
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment