From 39f5f6d452a8cce9990fe9469b3c9b11fd699d38 Mon Sep 17 00:00:00 2001 From: Carter Date: Mon, 25 Nov 2024 19:17:59 -0600 Subject: [PATCH] responsive container automatically generates cells based on object keys and values if no column data is provided --- src/common/ResponsiveTable.tsx | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/common/ResponsiveTable.tsx b/src/common/ResponsiveTable.tsx index a232654..07a9f62 100644 --- a/src/common/ResponsiveTable.tsx +++ b/src/common/ResponsiveTable.tsx @@ -49,7 +49,7 @@ interface Props { multiGutter?: boolean; } -export default function ResponsiveTable(props: Props) { +export default function ResponsiveTable(props: Props) { const { rows, total, @@ -61,7 +61,8 @@ export default function ResponsiveTable(props: Props) { renderGutter, setSearchText, isLoading, - multiGutter + multiGutter, + columns } = props const classes = useStyles(); @@ -135,7 +136,17 @@ export default function ResponsiveTable(props: Props) { { renderGutter && } - Profile + { columns ? + null + : rows.length > 0 && + Object.keys(rows[0]).map((value, index) => { + return( + + {value.toString()} + + ) + }) + } @@ -150,7 +161,7 @@ export default function ResponsiveTable(props: Props) { : rows.map((row, index) => { return ( - + {renderGutter && @@ -164,10 +175,21 @@ export default function ResponsiveTable(props: Props) { } + {columns ? + null + : + Object.values(row).map((value, j) => { + return ( + + {value.toString()} + + ) + }) + } {renderGutter && - + {renderGutter(row)}