Re-do css on tables, to do the whole table as divs with display: grid

This commit is contained in:
2024-07-25 08:37:37 -05:00
parent d9de96ea7f
commit 97bab57974
3 changed files with 119 additions and 128 deletions

View File

@ -321,16 +321,18 @@ function DataTable({
innerBoxStyle = {overflowY: "auto", scrollbarGutter: "stable"}; innerBoxStyle = {overflowY: "auto", scrollbarGutter: "stable"};
} }
///////////////////////////////////////////////////////////////////////////////////
// note - at one point, we had the table's sx including: whiteSpace: "nowrap"... //
///////////////////////////////////////////////////////////////////////////////////
return <Box sx={boxStyle}><Box sx={innerBoxStyle}> return <Box sx={boxStyle}><Box sx={innerBoxStyle}>
<Table {...getTableProps()}> <Table {...getTableProps()} component="div" sx={{display: "grid", gridTemplateRows: "auto", gridTemplateColumns: gridTemplateColumns}}>
{ {
includeHead && ( includeHead && (
<Box component="thead" sx={{position: "sticky", top: 0, background: "white", zIndex: 10}}> headerGroups.map((headerGroup: any, i: number) => (
{headerGroups.map((headerGroup: any, i: number) => ( headerGroup.headers.map((column: any) => (
<TableRow key={i} {...headerGroup.getHeaderGroupProps()} sx={{display: "grid", alignItems: "flex-end", gridTemplateColumns: gridTemplateColumns}}>
{headerGroup.headers.map((column: any) => (
column.type !== "hidden" && ( column.type !== "hidden" && (
<DataTableHeadCell <DataTableHeadCell
sx={{position: "sticky", top: 0, background: "white", zIndex: 10, alignItems: "flex-end"}}
key={i++} key={i++}
{...column.getHeaderProps(isSorted && column.getSortByToggleProps())} {...column.getHeaderProps(isSorted && column.getSortByToggleProps())}
align={column.align ? column.align : "left"} align={column.align ? column.align : "left"}
@ -340,13 +342,10 @@ function DataTable({
{column.render("header")} {column.render("header")}
</DataTableHeadCell> </DataTableHeadCell>
) )
))} ))
</TableRow> ))
))}
</Box>
) )
} }
<TableBody {...getTableBodyProps()}>
{rows.map((row: any, key: any) => {rows.map((row: any, key: any) =>
{ {
prepareRow(row); prepareRow(row);
@ -384,11 +383,11 @@ function DataTable({
} }
return ( return (
<TableRow sx={{verticalAlign: "top", display: "grid", gridTemplateColumns: gridTemplateColumns, background: background}} key={key} {...row.getRowProps()}> row.cells.map((cell: any) => (
{row.cells.map((cell: any) => (
cell.column.type !== "hidden" && ( cell.column.type !== "hidden" && (
<DataTableBodyCell <DataTableBodyCell
key={key} key={key}
sx={{verticalAlign: "top", background: background}}
noBorder={noEndBorder || overrideNoEndBorder || row.isExpanded} noBorder={noEndBorder || overrideNoEndBorder || row.isExpanded}
depth={row.depth} depth={row.depth}
align={cell.column.align ? cell.column.align : "left"} align={cell.column.align ? cell.column.align : "left"}
@ -446,12 +445,9 @@ function DataTable({
} }
</DataTableBodyCell> </DataTableBodyCell>
) )
))} ))
</TableRow>
); );
})} })}
</TableBody>
</Table> </Table>
</Box></Box>; </Box></Box>;
} }

View File

@ -36,7 +36,7 @@ function DataTableBodyCell({noBorder, align, children}: Props): JSX.Element
{ {
return ( return (
<Box <Box
component="td" component="div"
textAlign={align} textAlign={align}
py={1.5} py={1.5}
px={1.5} px={1.5}

View File

@ -44,18 +44,13 @@ function DataTableHeadCell({width, children, sorted, align, tooltip, ...rest}: P
return ( return (
<Box <Box
component="th" component="div"
width={width} width={width}
py={1.5} py={1.5}
px={1.5} px={1.5}
sx={({palette: {light}, borders: {borderWidth}}: Theme) => ({ sx={({palette: {light}, borders: {borderWidth}}: Theme) => ({
borderBottom: `${borderWidth[1]} solid ${colors.grayLines.main}`, borderBottom: `${borderWidth[1]} solid ${colors.grayLines.main}`,
"&:nth-of-type(1)": { position: "sticky", top: 0, background: "white"
paddingLeft: "1rem"
},
"&:last-child": {
paddingRight: "1rem"
},
})} })}
> >
<Box <Box