solve header table colorize
This commit is contained in:
@@ -47,12 +47,13 @@ const DataTable_TableHead = ({
|
|||||||
>
|
>
|
||||||
{table
|
{table
|
||||||
.getHeaderGroups()
|
.getHeaderGroups()
|
||||||
.map((headerGroup) => (
|
.map((headerGroup, index) => (
|
||||||
<DataTable_TableHeadRow
|
<DataTable_TableHeadRow
|
||||||
columnVirtualizer={columnVirtualizer}
|
columnVirtualizer={columnVirtualizer}
|
||||||
headerGroup={headerGroup}
|
headerGroup={headerGroup}
|
||||||
key={headerGroup.id}
|
key={headerGroup.id}
|
||||||
table={table}
|
table={table}
|
||||||
|
index={index}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,6 +262,9 @@ const DataTable_TableHeadCell = ({
|
|||||||
minWidth: `${Math.min(columnDef.header?.length ?? 0, 4)}ch`,
|
minWidth: `${Math.min(columnDef.header?.length ?? 0, 4)}ch`,
|
||||||
overflow: columnDefType === 'data' ? 'hidden' : undefined,
|
overflow: columnDefType === 'data' ? 'hidden' : undefined,
|
||||||
textOverflow: 'ellipsis',
|
textOverflow: 'ellipsis',
|
||||||
|
color: "#fff",
|
||||||
|
fontSize: "14px",
|
||||||
|
fontWeight: "500",
|
||||||
whiteSpace:
|
whiteSpace:
|
||||||
(columnDef.header?.length ?? 0) < 20
|
(columnDef.header?.length ?? 0) < 20
|
||||||
? 'nowrap'
|
? 'nowrap'
|
||||||
@@ -271,7 +274,8 @@ const DataTable_TableHeadCell = ({
|
|||||||
{HeaderElement}
|
{HeaderElement}
|
||||||
</Box>
|
</Box>
|
||||||
{(column.getCanSort() && columnDefType !== 'group') && (
|
{(column.getCanSort() && columnDefType !== 'group') && (
|
||||||
<MRT_TableHeadCellSortLabel sx={{ width: 20 }} header={header} table={table} />
|
<MRT_TableHeadCellSortLabel sx={{width: 20, color: "#fff"}} header={header}
|
||||||
|
table={table}/>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -6,54 +6,41 @@ const DataTable_TableHeadRow = ({
|
|||||||
columnVirtualizer,
|
columnVirtualizer,
|
||||||
headerGroup,
|
headerGroup,
|
||||||
table,
|
table,
|
||||||
|
index, // Add index prop
|
||||||
...rest
|
...rest
|
||||||
}) => {
|
}) => {
|
||||||
const {
|
const {
|
||||||
options: {
|
options: {
|
||||||
enableStickyHeader,
|
enableStickyHeader,
|
||||||
layoutMode,
|
layoutMode,
|
||||||
mrtTheme: { baseBackgroundColor },
|
|
||||||
muiTableHeadRowProps,
|
muiTableHeadRowProps,
|
||||||
},
|
},
|
||||||
} = table;
|
} = table;
|
||||||
|
|
||||||
const {virtualColumns, virtualPaddingLeft, virtualPaddingRight} =
|
const {virtualColumns, virtualPaddingLeft, virtualPaddingRight} =
|
||||||
columnVirtualizer ?? {};
|
columnVirtualizer ?? {};
|
||||||
|
|
||||||
|
const backgroundColor = index % 2 === 0 ? '#2070af' : '#ff5c0f';
|
||||||
|
|
||||||
const tableRowProps = {
|
const tableRowProps = {
|
||||||
...parseFromValuesOrFunc(muiTableHeadRowProps, {
|
...parseFromValuesOrFunc(muiTableHeadRowProps, {
|
||||||
headerGroup,
|
headerGroup,
|
||||||
table,
|
table,
|
||||||
}),
|
}),
|
||||||
...rest,
|
...rest,
|
||||||
|
sx: (theme) => ({ // Access theme from the sx function
|
||||||
|
...(parseFromValuesOrFunc(muiTableHeadRowProps?.sx, theme) || {}),
|
||||||
|
backgroundColor, // Apply background color
|
||||||
|
display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
|
||||||
|
position: enableStickyHeader && layoutMode === 'semantic' ? 'sticky' : 'relative',
|
||||||
|
top: 0,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow
|
<TableRow {...tableRowProps}>
|
||||||
{...tableRowProps}
|
{virtualPaddingLeft && <th style={{display: 'flex', width: virtualPaddingLeft}}/>}
|
||||||
sx={(theme) => ({
|
{(virtualColumns ?? headerGroup.headers).map((headerOrVirtualHeader, staticColumnIndex) => {
|
||||||
backgroundColor: baseBackgroundColor,
|
const header = columnVirtualizer ? headerGroup.headers[headerOrVirtualHeader.index] : headerOrVirtualHeader;
|
||||||
display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
|
|
||||||
position:
|
|
||||||
enableStickyHeader && layoutMode === 'semantic'
|
|
||||||
? 'sticky'
|
|
||||||
: 'relative',
|
|
||||||
top: 0,
|
|
||||||
...(parseFromValuesOrFunc(tableRowProps?.sx, theme)),
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
{virtualPaddingLeft ? (
|
|
||||||
<th style={{ display: 'flex', width: virtualPaddingLeft }} />
|
|
||||||
) : null}
|
|
||||||
{(virtualColumns ?? headerGroup.headers).map(
|
|
||||||
(headerOrVirtualHeader, staticColumnIndex) => {
|
|
||||||
let header = headerOrVirtualHeader;
|
|
||||||
|
|
||||||
if (columnVirtualizer) {
|
|
||||||
staticColumnIndex = (headerOrVirtualHeader)
|
|
||||||
.index;
|
|
||||||
header = headerGroup.headers[staticColumnIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
return header ? (
|
return header ? (
|
||||||
<DataTable_TableHeadCell
|
<DataTable_TableHeadCell
|
||||||
@@ -64,13 +51,10 @@ const DataTable_TableHeadRow = ({
|
|||||||
table={table}
|
table={table}
|
||||||
/>
|
/>
|
||||||
) : null;
|
) : null;
|
||||||
},
|
})}
|
||||||
)}
|
{virtualPaddingRight && <th style={{display: 'flex', width: virtualPaddingRight}}/>}
|
||||||
{virtualPaddingRight ? (
|
|
||||||
<th style={{ display: 'flex', width: virtualPaddingRight }} />
|
|
||||||
) : null}
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
export default DataTable_TableHeadRow;
|
||||||
export default DataTable_TableHeadRow
|
|
||||||
Reference in New Issue
Block a user