Created
October 24, 2022 14:22
-
-
Save peterkarn/b241f470c0b2b7196dff6dc3f3a8a57d to your computer and use it in GitHub Desktop.
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 characters
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