Skip to content

Fix: #1415 virtualized columns not works with grouped header #1438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type DragEvent, useMemo } from 'react';
import { type DragEvent, useMemo, useCallback } from 'react';
import Box from '@mui/material/Box';
import TableCell, { type TableCellProps } from '@mui/material/TableCell';
import { useTheme } from '@mui/material/styles';
Expand Down Expand Up @@ -159,6 +159,20 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
});
};

const handleRef = useCallback(
(node: HTMLTableCellElement) => {
if (node) {
if (tableHeadCellRefs.current) {
tableHeadCellRefs.current[column.id] = node;
}
if (columnDefType !== 'group') {
columnVirtualizer?.measureElement?.(node);
}
}
},
[column.id, columnDefType, columnVirtualizer, tableHeadCellRefs],
);

const HeaderElement =
parseFromValuesOrFunc(columnDef.Header, {
column,
Expand Down Expand Up @@ -189,14 +203,7 @@ export const MRT_TableHeadCell = <TData extends MRT_RowData>({
data-sort={column.getIsSorted() || undefined}
onDragEnter={handleDragEnter}
onDragOver={handleDragOver}
ref={(node: HTMLTableCellElement) => {
if (node) {
tableHeadCellRefs.current![column.id] = node;
if (columnDefType !== 'group') {
columnVirtualizer?.measureElement?.(node);
}
}
}}
ref={handleRef}
tabIndex={enableKeyboardShortcuts ? 0 : undefined}
{...tableCellProps}
onKeyDown={handleKeyDown}
Expand Down