fix:memperbaiki pagination pada tabel history
This commit is contained in:
parent
357611bd50
commit
bb70f00aae
|
@ -162,6 +162,7 @@ const TabelHistory = () => {
|
|||
<h3 className="w-full">Menampilkan {filteredData.length} data</h3>
|
||||
<Pagination className="flex justify-end">
|
||||
<PaginationContent>
|
||||
|
||||
<PaginationItem>
|
||||
<PaginationPrevious
|
||||
href="#"
|
||||
|
@ -170,17 +171,36 @@ const TabelHistory = () => {
|
|||
/>
|
||||
</PaginationItem>
|
||||
|
||||
{Array.from({ length: totalPages }, (_, index) => (
|
||||
<PaginationItem key={index}>
|
||||
|
||||
{(() => {
|
||||
let startPage = Math.max(1, currentPage - 1);
|
||||
let endPage = Math.min(totalPages, currentPage + 1);
|
||||
|
||||
|
||||
if (currentPage === 1) {
|
||||
endPage = Math.min(3, totalPages);
|
||||
}
|
||||
|
||||
|
||||
if (currentPage === totalPages) {
|
||||
startPage = Math.max(1, totalPages - 2);
|
||||
}
|
||||
|
||||
return Array.from({ length: endPage - startPage + 1 }, (_, i) => startPage + i).map(
|
||||
(page) => (
|
||||
<PaginationItem key={page}>
|
||||
<PaginationLink
|
||||
href="#"
|
||||
isActive={currentPage === index + 1}
|
||||
onClick={() => setCurrentPage(index + 1)}
|
||||
isActive={currentPage === page}
|
||||
onClick={() => setCurrentPage(page)}
|
||||
>
|
||||
{index + 1}
|
||||
{page}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
))}
|
||||
)
|
||||
);
|
||||
})()}
|
||||
|
||||
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
|
|
Loading…
Reference in New Issue