Add empty view to table

This commit is contained in:
Alex Holliday committed 2025-01-03 11:14:23 -08:00
1 parent 3d067e8030
commit c192d7024e
1 file changed
+15 -3
+15 -3
View File
@@ -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,7 +58,17 @@ const DataTable = ({ headers, data, config }) => {
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody> <TableBody>
{data.map((row) => { {data.length === 0 ? (
<TableRow>
<TableCell
colSpan={headers.length}
align="center"
>
{config.emptyView}
</TableCell>
</TableRow>
) : (
data.map((row) => {
return ( return (
<TableRow <TableRow
key={row.id} key={row.id}
@@ -77,7 +87,8 @@ const DataTable = ({ headers, data, config }) => {
})} })}
</TableRow> </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,
}), }),
}; };