responsive container automatically generates cells based on object keys and values if no column data is provided
This commit is contained in:
parent
8265914627
commit
39f5f6d452
1 changed files with 27 additions and 5 deletions
|
|
@ -49,7 +49,7 @@ interface Props<T> {
|
||||||
multiGutter?: boolean;
|
multiGutter?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ResponsiveTable<T>(props: Props<T>) {
|
export default function ResponsiveTable<T extends Object>(props: Props<T>) {
|
||||||
const {
|
const {
|
||||||
rows,
|
rows,
|
||||||
total,
|
total,
|
||||||
|
|
@ -61,7 +61,8 @@ export default function ResponsiveTable<T>(props: Props<T>) {
|
||||||
renderGutter,
|
renderGutter,
|
||||||
setSearchText,
|
setSearchText,
|
||||||
isLoading,
|
isLoading,
|
||||||
multiGutter
|
multiGutter,
|
||||||
|
columns
|
||||||
} = props
|
} = props
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
|
|
@ -135,7 +136,17 @@ export default function ResponsiveTable<T>(props: Props<T>) {
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
{ renderGutter && <TableCell></TableCell>}
|
{ renderGutter && <TableCell></TableCell>}
|
||||||
<TableCell>Profile</TableCell>
|
{ columns ?
|
||||||
|
null
|
||||||
|
: rows.length > 0 &&
|
||||||
|
Object.keys(rows[0]).map((value, index) => {
|
||||||
|
return(
|
||||||
|
<TableCell key={"header-cell-"+index}>
|
||||||
|
{value.toString()}
|
||||||
|
</TableCell>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
|
|
@ -150,7 +161,7 @@ export default function ResponsiveTable<T>(props: Props<T>) {
|
||||||
:
|
:
|
||||||
rows.map((row, index) => {
|
rows.map((row, index) => {
|
||||||
return (
|
return (
|
||||||
<React.Fragment key={"user-row-"+index}>
|
<React.Fragment key={"row-"+index}>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
{renderGutter &&
|
{renderGutter &&
|
||||||
<TableCell width={1}>
|
<TableCell width={1}>
|
||||||
|
|
@ -164,10 +175,21 @@ export default function ResponsiveTable<T>(props: Props<T>) {
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
}
|
}
|
||||||
|
{columns ?
|
||||||
|
null
|
||||||
|
:
|
||||||
|
Object.values(row).map((value, j) => {
|
||||||
|
return (
|
||||||
|
<TableCell key={"row-"+index+"cell-"+j}>
|
||||||
|
{value.toString()}
|
||||||
|
</TableCell>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
{renderGutter &&
|
{renderGutter &&
|
||||||
<TableRow className={classes.gutter}>
|
<TableRow className={classes.gutter}>
|
||||||
<TableCell colSpan={6} style={{padding:0, margin: 0, border: "none"}}>
|
<TableCell colSpan={6} sx={{padding:0, margin: 0, border: "none"}}>
|
||||||
<Collapse in={openGutters.includes(index)} timeout="auto" unmountOnExit>
|
<Collapse in={openGutters.includes(index)} timeout="auto" unmountOnExit>
|
||||||
{renderGutter(row)}
|
{renderGutter(row)}
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue