@@ -75,35 +75,20 @@ export function getCellProps<RecordType>(
75
75
let additionalCellProps : React . TdHTMLAttributes < HTMLElement > ;
76
76
if ( column . onCell ) {
77
77
additionalCellProps = column . onCell ( record , index ) ;
78
- // 开启 expanded 的增加下面逻辑
79
- if ( expandable ) {
80
- // 当前为合并单元格开始
81
- if ( additionalCellProps . rowSpan > 0 ) {
82
- // 本身展开 +1
83
- if ( expanded ) {
84
- additionalCellProps . rowSpan = additionalCellProps . rowSpan + 1 ;
78
+ const { rowSpan } = additionalCellProps ;
79
+
80
+ // For expandable row with rowSpan,
81
+ // We should increase the rowSpan if the row is expanded
82
+ if ( expandable && rowSpan > 1 ) {
83
+ let currentRowSpan = rowSpan ;
84
+
85
+ for ( let i = index ; i < rowSpan ; i += 1 ) {
86
+ const rowKey = rowKeys [ i ] ;
87
+ if ( expandedKeys . has ( rowKey ) ) {
88
+ currentRowSpan += 1 ;
85
89
}
86
- // 下面如果是 0 的,增加 +1 逻辑
87
- const addChildrenRowSpan = ( rowSpan : number , idx : number ) => {
88
- const nextIndex = idx + 1 ;
89
- const rowKey = rowKeys [ nextIndex ] ;
90
- let _rowSpan = rowSpan ;
91
- if ( rowKey !== undefined ) {
92
- const thisCellProps = column . onCell ( record , nextIndex ) ;
93
- if ( thisCellProps . rowSpan === 0 ) {
94
- const thisExpanded = expandedKeys . has ( rowKey ) ;
95
- if ( thisExpanded ) {
96
- _rowSpan = _rowSpan + 1 ;
97
- }
98
- // 继续往下找
99
- return addChildrenRowSpan ( _rowSpan , nextIndex ) ;
100
- }
101
- }
102
- // 找不到后返回
103
- return _rowSpan ;
104
- } ;
105
- additionalCellProps . rowSpan = addChildrenRowSpan ( additionalCellProps . rowSpan , index ) ;
106
90
}
91
+ additionalCellProps . rowSpan = currentRowSpan ;
107
92
}
108
93
}
109
94
0 commit comments