-
-
Save royhowie/0bd805d197c210bbf3eb to your computer and use it in GitHub Desktop.
pagination page generator
This file contains 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
const PAGES_ON_ENDS = 3 | |
function getPages (currentPage, perPage, total) { | |
let maxPage = Math.floor(total / perPage) | |
let lower = Math.max(currentPage - PAGES_ON_ENDS, 0) | |
let upper = Math.min(currentPage + PAGES_ON_ENDS, maxPage) | |
return Array.from(Array(upper - lower + 1), (_, i) => lower + i) | |
} |
This file contains 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
const PAGES_ON_ENDS = 3 | |
function getPages (currentPage, perPage, total) { | |
let maxPage = Math.floor(total / perPage) | |
let arr = [] | |
let lower = Math.max(currentPage - PAGES_ON_ENDS, 0) | |
let upper = Math.min(currentPage + PAGES_ON_ENDS, maxPage) | |
for (let i = lower; i <= upper; i++) { | |
arr.push(i) | |
} | |
return arr | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment