Skip to content

Commit b31ea41

Browse files
committed
fix(getColumnsKey): allow empty string && getColumnsKey in BodyGrid
1 parent c8d2df1 commit b31ea41

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/VirtualTable/BodyGrid.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import useFlattenRecords, { type FlattenData } from '../hooks/useFlattenRecords'
66
import type { ColumnType, OnCustomizeScroll, ScrollConfig } from '../interface';
77
import BodyLine from './BodyLine';
88
import { GridContext, StaticContext } from './context';
9+
import { getColumnsKey } from '../utils/valueUtil';
910

1011
export interface GridProps<RecordType = any> {
1112
data: RecordType[];
@@ -58,7 +59,9 @@ const Grid = React.forwardRef<GridRef, GridProps>((props, ref) => {
5859
// ========================== Column ==========================
5960
const columnsWidth = React.useMemo<[key: React.Key, width: number, total: number][]>(() => {
6061
let total = 0;
61-
return flattenColumns.map(({ width, minWidth, key }) => {
62+
const columnKeys = getColumnsKey(flattenColumns);
63+
return flattenColumns.map(({ width, minWidth }, index) => {
64+
const key = columnKeys[index];
6265
const finalWidth = Math.max((width as number) || 0, (minWidth as number) || 0);
6366
total += finalWidth;
6467
return [key, finalWidth, total];

src/utils/valueUtil.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function getColumnsKey<T = any>(columns: readonly GetColumnKeyColumn<T>[]
2121
columns.forEach(column => {
2222
const { key, dataIndex } = column || {};
2323

24-
let mergedKey = key || toArray(dataIndex).join('-') || INTERNAL_KEY_PREFIX;
24+
let mergedKey = key ?? toArray(dataIndex).join('-') ?? INTERNAL_KEY_PREFIX;
2525
while (keys[mergedKey as string]) {
2626
mergedKey = `${mergedKey}_next`;
2727
}

0 commit comments

Comments
 (0)