Add empty view to table
This commit is contained in:
1 parent
3d067e8030
commit
c192d7024e
1 file changed
+32
-20
@@ -35,7 +35,7 @@ import { useTheme } from "@emotion/react";
|
|||||||
const DataTable = ({ headers, data, config }) => {
|
const DataTable = ({ headers, data, config }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
if ((headers?.length ?? 0) === 0 || (data?.length ?? 0) === 0) {
|
if ((headers?.length ?? 0) === 0) {
|
||||||
return "No data";
|
return "No data";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,26 +58,37 @@ const DataTable = ({ headers, data, config }) => {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((row) => {
|
{data.length === 0 ? (
|
||||||
return (
|
<TableRow>
|
||||||
<TableRow
|
<TableCell
|
||||||
key={row.id}
|
colSpan={headers.length}
|
||||||
sx={config?.rowSX ?? {}}
|
align="center"
|
||||||
onClick={() => config?.onRowClick(row)}
|
|
||||||
>
|
>
|
||||||
{headers.map((header, index) => {
|
{config.emptyView}
|
||||||
return (
|
</TableCell>
|
||||||
<TableCell
|
</TableRow>
|
||||||
align={index === 0 ? "left" : "center"}
|
) : (
|
||||||
key={header.id}
|
data.map((row) => {
|
||||||
>
|
return (
|
||||||
{header.render(row)}
|
<TableRow
|
||||||
</TableCell>
|
key={row.id}
|
||||||
);
|
sx={config?.rowSX ?? {}}
|
||||||
})}
|
onClick={() => config?.onRowClick(row)}
|
||||||
</TableRow>
|
>
|
||||||
);
|
{headers.map((header, index) => {
|
||||||
})}
|
return (
|
||||||
|
<TableCell
|
||||||
|
align={index === 0 ? "left" : "center"}
|
||||||
|
key={header.id}
|
||||||
|
>
|
||||||
|
{header.render(row)}
|
||||||
|
</TableCell>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TableRow>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</TableContainer>
|
</TableContainer>
|
||||||
@@ -96,6 +107,7 @@ DataTable.propTypes = {
|
|||||||
config: PropTypes.shape({
|
config: PropTypes.shape({
|
||||||
onRowClick: PropTypes.func.isRequired,
|
onRowClick: PropTypes.func.isRequired,
|
||||||
rowSX: PropTypes.object,
|
rowSX: PropTypes.object,
|
||||||
|
emptyView: PropTypes.node,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user