-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26a5567
commit 80aed93
Showing
22 changed files
with
2,659 additions
and
5,109 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
101 changes: 59 additions & 42 deletions
101
src/UIs/bff/reactjs/src/components/Pagination/Pagination.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,62 @@ | ||
import { Pagination as BootstrapPagination } from "react-bootstrap"; | ||
|
||
const Pagination = (props) => { | ||
const { totalItems, currentPage, pageSize } = props; | ||
const totalPages = Math.ceil(totalItems / pageSize); | ||
|
||
const pageNumbers: Array<number> = []; | ||
let startIndex = currentPage - 2; | ||
let endIndex = currentPage + 2; | ||
|
||
if (startIndex < 1) { | ||
endIndex = endIndex + (1 - startIndex); | ||
startIndex = 1; | ||
} | ||
|
||
if (endIndex > totalPages) { | ||
startIndex = startIndex - (endIndex - totalPages); | ||
endIndex = totalPages; | ||
} | ||
|
||
startIndex = Math.max(startIndex, 1); | ||
endIndex = Math.min(endIndex, totalPages); | ||
|
||
for (let i = startIndex; i <= endIndex; i++) { | ||
pageNumbers.push(i); | ||
} | ||
|
||
const pageSelected = (page: number) => { | ||
props.pageSelected(page); | ||
} | ||
|
||
const pageItems = pageNumbers.map((index) => ( | ||
<BootstrapPagination.Item active={currentPage === index} onClick={() => pageSelected(index)}>{index}</BootstrapPagination.Item> | ||
)); | ||
|
||
return (<BootstrapPagination> | ||
<BootstrapPagination.First disabled={currentPage === 1} onClick={() => pageSelected(1)} /> | ||
<BootstrapPagination.Prev disabled={currentPage === 1} onClick={() => pageSelected(currentPage - 1)} /> | ||
{pageItems} | ||
<BootstrapPagination.Next disabled={currentPage === totalPages} onClick={() => pageSelected(currentPage + 1)} /> | ||
<BootstrapPagination.Last disabled={currentPage === totalPages} onClick={() => pageSelected(totalPages)} /> | ||
</BootstrapPagination>); | ||
} | ||
|
||
export default Pagination; | ||
const { totalItems, currentPage, pageSize } = props; | ||
const totalPages = Math.ceil(totalItems / pageSize); | ||
|
||
const pageNumbers: Array<number> = []; | ||
let startIndex = currentPage - 2; | ||
let endIndex = currentPage + 2; | ||
|
||
if (startIndex < 1) { | ||
endIndex = endIndex + (1 - startIndex); | ||
startIndex = 1; | ||
} | ||
|
||
if (endIndex > totalPages) { | ||
startIndex = startIndex - (endIndex - totalPages); | ||
endIndex = totalPages; | ||
} | ||
|
||
startIndex = Math.max(startIndex, 1); | ||
endIndex = Math.min(endIndex, totalPages); | ||
|
||
for (let i = startIndex; i <= endIndex; i++) { | ||
pageNumbers.push(i); | ||
} | ||
|
||
const pageSelected = (page: number) => { | ||
props.pageSelected(page); | ||
}; | ||
|
||
const pageItems = pageNumbers.map((index) => ( | ||
<BootstrapPagination.Item | ||
key={index} | ||
active={currentPage === index} | ||
onClick={() => pageSelected(index)} | ||
> | ||
{index} | ||
</BootstrapPagination.Item> | ||
)); | ||
|
||
return ( | ||
<BootstrapPagination> | ||
<BootstrapPagination.First disabled={currentPage === 1} onClick={() => pageSelected(1)} /> | ||
<BootstrapPagination.Prev | ||
disabled={currentPage === 1} | ||
onClick={() => pageSelected(currentPage - 1)} | ||
/> | ||
{pageItems} | ||
<BootstrapPagination.Next | ||
disabled={currentPage === totalPages} | ||
onClick={() => pageSelected(currentPage + 1)} | ||
/> | ||
<BootstrapPagination.Last | ||
disabled={currentPage === totalPages} | ||
onClick={() => pageSelected(totalPages)} | ||
/> | ||
</BootstrapPagination> | ||
); | ||
}; | ||
|
||
export default Pagination; |
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
Oops, something went wrong.