diff --git a/frontend/src/components/common/Table/Table.tsx b/frontend/src/components/common/Table/Table.tsx index 93233597a5..a949bd17fb 100644 --- a/frontend/src/components/common/Table/Table.tsx +++ b/frontend/src/components/common/Table/Table.tsx @@ -7,7 +7,6 @@ import { MRT_ColumnDef as MaterialTableColumn, MRT_Header, MRT_Localization, - MRT_Row, MRT_TableBodyCell, MRT_TableHeadCell, MRT_TableInstance, @@ -191,34 +190,6 @@ export default function Table>({ return (tableProps.data ?? []).filter(it => filterFunction(it)); }, [tableProps.data, filterFunction]); - const gridTemplateColumns = useMemo(() => { - let preGridTemplateColumns = tableProps.columns - .filter(it => { - const isHidden = tableProps.state?.columnVisibility?.[it.id!] === false; - return !isHidden; - }) - .map(it => { - if (typeof it.gridTemplate === 'number') { - return `${it.gridTemplate}fr`; - } - return it.gridTemplate ?? '1fr'; - }) - .join(' '); - if (tableProps.enableRowActions) { - preGridTemplateColumns = `${preGridTemplateColumns} 0.05fr`; - } - if (tableProps.enableRowSelection) { - preGridTemplateColumns = `44px ${preGridTemplateColumns}`; - } - - return preGridTemplateColumns; - }, [ - tableProps.columns, - tableProps.state?.columnVisibility, - tableProps.enableRowActions, - tableProps.enableRowSelection, - ]); - const paginationSelectProps = import.meta.env.UNDER_TEST ? { inputProps: { @@ -325,6 +296,38 @@ export default function Table>({ }, }); + const gridTemplateColumns = useMemo(() => { + let preGridTemplateColumns = tableProps.columns + .filter((it, i) => { + const id = it.id ?? String(i); + const isHidden = + table.getState().columnVisibility?.[id] === false || + tableProps.state?.columnVisibility?.[id] === false; + return !isHidden; + }) + .map(it => { + if (typeof it.gridTemplate === 'number') { + return `${it.gridTemplate}fr`; + } + return it.gridTemplate ?? '1fr'; + }) + .join(' '); + if (tableProps.enableRowActions) { + preGridTemplateColumns = `${preGridTemplateColumns} 0.05fr`; + } + if (tableProps.enableRowSelection) { + preGridTemplateColumns = `44px ${preGridTemplateColumns}`; + } + + return preGridTemplateColumns; + }, [ + tableProps.columns, + table.getState()?.columnVisibility, + tableProps.state?.columnVisibility, + tableProps.enableRowActions, + tableProps.enableRowSelection, + ]); + const rows = useMRT_Rows(table); if (!!errorMessage) { @@ -382,7 +385,12 @@ export default function Table>({ {rows.map(row => ( - + ))} @@ -417,16 +425,16 @@ const MemoHeadCell = memo( const Row = memo( ({ - row, + cells, table, isSelected, }: { table: MRT_TableInstance; - row: MRT_Row; + cells: MRT_Cell[]; isSelected: boolean; }) => ( - {row.getVisibleCells().map(cell => ( + {cells.map(cell => (