Skip to content

Commit c2a49ed

Browse files
authored
fix: when the children of the table column is falsely still recognized as a column group (#430)
* 修复当,外围存在一些逻辑操作columus时 如reduce, 会对无效的group 识别为group * inline as
1 parent f8eb6a0 commit c2a49ed

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/Header/Header.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import * as React from 'react';
2-
import { ColumnsType, CellType, StickyOffsets, ColumnType, GetComponentProps } from '../interface';
2+
import {
3+
ColumnsType,
4+
CellType,
5+
StickyOffsets,
6+
ColumnType,
7+
GetComponentProps,
8+
ColumnGroupType,
9+
} from '../interface';
310
import HeaderRow from './HeaderRow';
411
import TableContext from '../context/TableContext';
512

@@ -28,11 +35,12 @@ function parseHeaderRows<RecordType>(
2835

2936
let colSpan: number = 1;
3037

31-
if ('children' in column) {
32-
colSpan = fillRowCells(column.children, currentColIndex, rowIndex + 1).reduce(
33-
(total, count) => total + count,
34-
0,
35-
);
38+
if ((column as ColumnGroupType<RecordType>).children) {
39+
colSpan = fillRowCells(
40+
(column as ColumnGroupType<RecordType>).children,
41+
currentColIndex,
42+
rowIndex + 1,
43+
).reduce((total, count) => total + count, 0);
3644
cell.hasSubColumns = true;
3745
}
3846

src/hooks/useColumns.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
GetRowKey,
1010
TriggerEventHandler,
1111
RenderExpandIcon,
12+
ColumnGroupType,
1213
} from '../interface';
1314
import { INTERNAL_COL_DEFINE } from '../utils/legacyUtil';
1415

@@ -39,10 +40,10 @@ function flatColumns<RecordType>(columns: ColumnsType<RecordType>): ColumnType<R
3940
// Convert `fixed='true'` to `fixed='left'` instead
4041
const parsedFixed = fixed === true ? 'left' : fixed;
4142

42-
if ('children' in column) {
43+
if ((column as ColumnGroupType<RecordType>).children) {
4344
return [
4445
...list,
45-
...flatColumns(column.children).map(subColum => ({
46+
...flatColumns((column as ColumnGroupType<RecordType>).children).map(subColum => ({
4647
fixed: parsedFixed,
4748
...subColum,
4849
})),

0 commit comments

Comments
 (0)