-2
I’m pulling an array with a size of about 20,000. However, at paging time, all available pages appear in my paging field.
But I wanted to narrow it down, so that only three numbers and like, 1 2 3 ... 10
render({
const indexOfLastUser = currentPage * usersPerPage
const indexOfFirstUser = indexOfLastUser - usersPerPage
const currentUsers = users.slice(indexOfFirstUser, indexOfLastUser)
const pageNumbers = []
for (let i = 1; i <= Math.ceil(users.length / usersPerPage); i++) {
pageNumbers.push(i)
}
const renderPageNumbers =
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item">
<a class="page-link" href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
{pageNumbers.map(number => {
return (
<li class="page-item"><a class="page-link" href="#" onClick={this.handleClick} key={number} id={number}>{number}</a></li>
)
})}
<li class="page-item">
<a class="page-link" href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
return(
{renderPageNumbers}
)}