pagination logic in calculating total of pages
Divide total_items
by limit
, and round the value up.
Math.ceil(total_items/limit);50 items / 10 per page = 5 pages55 items / 10 per page = 6 pages
you need to check if there is a quotient from the divide operation because there is apparently few items need to be showed in another page
for example:
6 items5 limit
if we just divide and ceil
we will get 1 which is incorrect because there is one item need an extra page to be counted
totalPages_pre = (total_items/limit)totalPages = (search.total % page_size) == 0 ? totalPages_pre : totalPages_pre + 1