fix:memperbaiki pagination pada tabel history
This commit is contained in:
parent
357611bd50
commit
bb70f00aae
|
@ -73,7 +73,7 @@ const TabelHistory = () => {
|
|||
const currentData = filteredData.slice(startIndex, endIndex);
|
||||
|
||||
|
||||
const handleDelete = async(id) => {
|
||||
const handleDelete = async (id) => {
|
||||
// setDataHarga((prevData) => prevData.filter((item) => item.id !== id));
|
||||
const token = localStorage.getItem("token");
|
||||
try {
|
||||
|
@ -141,7 +141,7 @@ const TabelHistory = () => {
|
|||
<TableCell className="text-center">{item.MAPE}%</TableCell>
|
||||
<TableCell className="text-center">
|
||||
<Button variant="destructive" size="sm" onClick={() => handleDelete(item.id)}>
|
||||
<Trash size={16}/>
|
||||
<Trash size={16} />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
@ -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