Skip to content

Commit f7dccfe

Browse files
author
Gianmarco Manni
committed
possibility to display CurrentItemPerPage in Pagination dropdown and to be re-selected after one change
1 parent b614ca9 commit f7dccfe

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- possibility to display CurrentItemPerPage in Pagination dropdown and to be re-selected after one change
13+
1014
## [2.1.1] - 2022-12-09
1115

1216
- Added styling for button groups

src/Paging/Paging.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,21 @@ function Paging({
2626
currentRecordCount,
2727
pagingPossible = true,
2828
translations,
29-
possiblePageItemCounts = [25, 50, 100, 200],
29+
possiblePageItemCounts,
3030
maxPagesShown = 7,
3131
showControls = true,
3232
setItemsPerPage,
3333
setCurrentPage,
3434
}: PagingProps) {
3535
const maxPage = Math.ceil(totalRecords / currentItemsPerPage);
3636
const firstPageShown = Math.max(0, Math.min(currentPage - Math.ceil(maxPagesShown / 2), maxPage - maxPagesShown));
37+
38+
const possibleItemsPerPage = possiblePageItemCounts ?? [25, 50, 100, 200];
39+
40+
if (!possibleItemsPerPage.includes(currentItemsPerPage)) {
41+
possibleItemsPerPage.concat(currentItemsPerPage).sort((a, b) => a-b);
42+
}
43+
3744
return (
3845
<Row style={{ marginBottom: "20px" }}>
3946
<Col xs={6}>
@@ -44,7 +51,7 @@ function Paging({
4451
</DropdownToggle>
4552
<DropdownMenu>
4653
<DropdownItem header>{translations.itemsPerPageDropdown}</DropdownItem>
47-
{possiblePageItemCounts.map((pageItemCount) => (
54+
{possibleItemsPerPage.map((pageItemCount) => (
4855
<DropdownItem key={`pageItemCount_${pageItemCount}`} onClick={() => setItemsPerPage(pageItemCount)}>
4956
{pageItemCount}
5057
</DropdownItem>

0 commit comments

Comments
 (0)