Skip to content

Commit

Permalink
Merge pull request #1413 from pierotofy/pagination
Browse files Browse the repository at this point in the history
Fix paginator overflow
  • Loading branch information
pierotofy authored Oct 5, 2023
2 parents 2d5a403 + bc86c79 commit 295bf3f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/static/app/js/components/Paginator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,16 @@ class Paginator extends React.Component {
}

if (itemsPerPage && itemsPerPage && totalItems > itemsPerPage){
const numPages = Math.ceil(totalItems / itemsPerPage),
pages = [...Array(numPages).keys()]; // [0, 1, 2, ...numPages]
const numPages = Math.ceil(totalItems / itemsPerPage);
const MAX_PAGE_BUTTONS = 7;

let rangeStart = Math.max(1, currentPage - Math.floor(MAX_PAGE_BUTTONS / 2));
let rangeEnd = rangeStart + Math.min(numPages, MAX_PAGE_BUTTONS);
if (rangeEnd > numPages){
rangeStart -= rangeEnd - numPages - 1;
rangeEnd -= rangeEnd - numPages - 1
}
let pages = [...Array(rangeEnd - rangeStart).keys()].map(i => i + rangeStart - 1);

paginator = (
<ul className="pagination pagination-sm">
Expand Down

0 comments on commit 295bf3f

Please sign in to comment.