I have 20 items in total, per page 5 items
How to calculate the page number if know id
of item in general using javascript.
Possible formula or way to calculate the page number by id value
example:
let itemsTotal = 20;
let perPage = 5;
let itemId=25;
let pageForThisProduct = Math.ceil(itemId/itemsTotal);
2
Answers
You’re close. You don’t divide the current item in the list by the number of items – you divide the current item by the number of items allowed per page (or limit).
You can use the following code to get the page number based on ID:
The variable pageForThisProduct will store the page number and you can display based on your functionality.