From bc86c7977b6ba281af8378cccd4b9a6294c31040 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Thu, 5 Oct 2023 12:47:28 -0400 Subject: [PATCH] Add max number of pages in paginator --- app/static/app/js/components/Paginator.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/static/app/js/components/Paginator.jsx b/app/static/app/js/components/Paginator.jsx index 6944f74f..cd3e1909 100644 --- a/app/static/app/js/components/Paginator.jsx +++ b/app/static/app/js/components/Paginator.jsx @@ -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 = (