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>
|
<h3 className="w-full">Menampilkan {filteredData.length} data</h3>
|
||||||
<Pagination className="flex justify-end">
|
<Pagination className="flex justify-end">
|
||||||
<PaginationContent>
|
<PaginationContent>
|
||||||
|
|
||||||
<PaginationItem>
|
<PaginationItem>
|
||||||
<PaginationPrevious
|
<PaginationPrevious
|
||||||
href="#"
|
href="#"
|
||||||
|
@ -170,17 +171,36 @@ const TabelHistory = () => {
|
||||||
/>
|
/>
|
||||||
</PaginationItem>
|
</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
|
<PaginationLink
|
||||||
href="#"
|
href="#"
|
||||||
isActive={currentPage === index + 1}
|
isActive={currentPage === page}
|
||||||
onClick={() => setCurrentPage(index + 1)}
|
onClick={() => setCurrentPage(page)}
|
||||||
>
|
>
|
||||||
{index + 1}
|
{page}
|
||||||
</PaginationLink>
|
</PaginationLink>
|
||||||
</PaginationItem>
|
</PaginationItem>
|
||||||
))}
|
)
|
||||||
|
);
|
||||||
|
})()}
|
||||||
|
|
||||||
|
|
||||||
<PaginationItem>
|
<PaginationItem>
|
||||||
<PaginationNext
|
<PaginationNext
|
||||||
|
|
Loading…
Reference in New Issue