Skip to content

fix: use headerGroup.headers when virtual columns are not available #1387

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
Expand Up @@ -10,6 +10,8 @@ import {
type MRT_VirtualItem,
} from '../../types';
import { parseFromValuesOrFunc } from '../../utils/utils';
import { useMemo } from 'react';
import { VirtualItem } from '@tanstack/react-virtual';

export interface MRT_TableHeadRowProps<TData extends MRT_RowData>
extends TableRowProps {
Expand Down Expand Up @@ -44,6 +46,11 @@ export const MRT_TableHeadRow = <TData extends MRT_RowData>({
...rest,
};

const headerColumns: VirtualItem[] | MRT_Header<TData>[] = useMemo(
() => (virtualColumns?.length ? virtualColumns : headerGroup.headers),
[headerGroup.headers, virtualColumns],
);

return (
<TableRow
{...tableRowProps}
Expand All @@ -62,26 +69,23 @@ export const MRT_TableHeadRow = <TData extends MRT_RowData>({
{virtualPaddingLeft ? (
<th style={{ display: 'flex', width: virtualPaddingLeft }} />
) : null}
{(virtualColumns ?? headerGroup.headers).map(
(headerOrVirtualHeader, staticColumnIndex) => {
let header = headerOrVirtualHeader as MRT_Header<TData>;
if (columnVirtualizer) {
staticColumnIndex = (headerOrVirtualHeader as MRT_VirtualItem)
.index;
header = headerGroup.headers[staticColumnIndex];
}
{headerColumns.map((headerOrVirtualHeader, staticColumnIndex) => {
let header = headerOrVirtualHeader as MRT_Header<TData>;
if (columnVirtualizer && virtualColumns?.length) {
staticColumnIndex = (headerOrVirtualHeader as MRT_VirtualItem).index;
header = headerGroup.headers[staticColumnIndex];
}

return header ? (
<MRT_TableHeadCell
columnVirtualizer={columnVirtualizer}
header={header}
key={header.id}
staticColumnIndex={staticColumnIndex}
table={table}
/>
) : null;
},
)}
return header ? (
<MRT_TableHeadCell
columnVirtualizer={columnVirtualizer}
header={header}
key={header.id}
staticColumnIndex={staticColumnIndex}
table={table}
/>
) : null;
})}
{virtualPaddingRight ? (
<th style={{ display: 'flex', width: virtualPaddingRight }} />
) : null}
Expand Down
Loading