Skip to content

Commit cab8551

Browse files
kwimokWimok Kuekittiwong
andauthored
Fix: #1415 virtualized columns not works with grouped header (#1438)
Co-authored-by: Wimok Kuekittiwong <wimok.kuekittiwong@cartrack.com>
1 parent a7a50b9 commit cab8551

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

packages/material-react-table/src/components/head/MRT_TableHeadCell.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type DragEvent, useMemo } from 'react';
1+
import { type DragEvent, useMemo, useCallback } from 'react';
22
import Box from '@mui/material/Box';
33
import TableCell, { type TableCellProps } from '@mui/material/TableCell';
44
import { useTheme } from '@mui/material/styles';
@@ -159,6 +159,20 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
159159
});
160160
};
161161

162+
const handleRef = useCallback(
163+
(node: HTMLTableCellElement) => {
164+
if (node) {
165+
if (tableHeadCellRefs.current) {
166+
tableHeadCellRefs.current[column.id] = node;
167+
}
168+
if (columnDefType !== 'group') {
169+
columnVirtualizer?.measureElement?.(node);
170+
}
171+
}
172+
},
173+
[column.id, columnDefType, columnVirtualizer, tableHeadCellRefs],
174+
);
175+
162176
const HeaderElement =
163177
parseFromValuesOrFunc(columnDef.Header, {
164178
column,
@@ -189,14 +203,7 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
189203
data-sort={column.getIsSorted() || undefined}
190204
onDragEnter={handleDragEnter}
191205
onDragOver={handleDragOver}
192-
ref={(node: HTMLTableCellElement) => {
193-
if (node) {
194-
tableHeadCellRefs.current![column.id] = node;
195-
if (columnDefType !== 'group') {
196-
columnVirtualizer?.measureElement?.(node);
197-
}
198-
}
199-
}}
206+
ref={handleRef}
200207
tabIndex={enableKeyboardShortcuts ? 0 : undefined}
201208
{...tableCellProps}
202209
onKeyDown={handleKeyDown}

0 commit comments

Comments
 (0)