2024-07-24 21:58:45 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import {Paper, Table, TableBody, TableCell, TableContainer, TableHead, TablePagination, TableRow} from "@mui/material";
|
|
|
|
|
|
|
|
|
|
interface Column {
|
|
|
|
|
id: string;
|
|
|
|
|
label: string;
|
|
|
|
|
minWidth?: number;
|
|
|
|
|
align?: 'right';
|
2024-07-25 02:09:49 +02:00
|
|
|
format?: (value: any) => any;
|
2024-07-24 21:58:45 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-25 02:09:49 +02:00
|
|
|
export default function HeadTable({columns, rows}: { rows: any[], columns: Column[] }) {
|
2024-07-24 21:58:45 +02:00
|
|
|
const [page, setPage] = React.useState(0);
|
|
|
|
|
const [rowsPerPage, setRowsPerPage] = React.useState(10);
|
|
|
|
|
|
|
|
|
|
const handleChangePage = (event: unknown, newPage: number) => {
|
|
|
|
|
setPage(newPage);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
setRowsPerPage(+event.target.value);
|
|
|
|
|
setPage(0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Paper sx={{width: '100%', overflow: 'hidden'}}>
|
2024-07-25 02:09:49 +02:00
|
|
|
<TableContainer>
|
|
|
|
|
<Table size="small">
|
2024-07-24 21:58:45 +02:00
|
|
|
<TableHead>
|
|
|
|
|
<TableRow>
|
|
|
|
|
{columns.map((column) => (
|
|
|
|
|
<TableCell
|
|
|
|
|
key={column.id}
|
|
|
|
|
align={column.align}
|
|
|
|
|
style={{minWidth: column.minWidth}}
|
|
|
|
|
>
|
|
|
|
|
{column.label}
|
|
|
|
|
</TableCell>
|
|
|
|
|
))}
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableHead>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{rows
|
|
|
|
|
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
|
2024-07-25 02:09:49 +02:00
|
|
|
.map((row: any) => {
|
2024-07-24 21:58:45 +02:00
|
|
|
return (
|
2024-07-25 02:09:49 +02:00
|
|
|
<TableRow hover sx={{'&:last-child td, &:last-child th': {border: 0}}}
|
|
|
|
|
role="checkbox" tabIndex={-1} key={row.code}>
|
2024-07-24 21:58:45 +02:00
|
|
|
{columns.map((column) => {
|
|
|
|
|
const value = row[column.id as keyof typeof row]
|
|
|
|
|
return (
|
|
|
|
|
<TableCell key={column.id} align={column.align}>
|
2024-07-25 02:09:49 +02:00
|
|
|
{column.format ? column.format(value) : value}
|
2024-07-24 21:58:45 +02:00
|
|
|
</TableCell>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</TableRow>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
</TableContainer>
|
|
|
|
|
<TablePagination
|
|
|
|
|
rowsPerPageOptions={[10, 25, 100]}
|
|
|
|
|
component="div"
|
|
|
|
|
count={rows.length}
|
|
|
|
|
rowsPerPage={rowsPerPage}
|
|
|
|
|
page={page}
|
|
|
|
|
onPageChange={handleChangePage}
|
|
|
|
|
onRowsPerPageChange={handleChangeRowsPerPage}
|
|
|
|
|
/>
|
|
|
|
|
</Paper>
|
|
|
|
|
);
|
|
|
|
|
}
|