@@ -7,7 +7,7 @@ import useRowInfo from '../hooks/useRowInfo';
7
7
import type { ColumnType , CustomizeComponent } from '../interface' ;
8
8
import ExpandedRow from './ExpandedRow' ;
9
9
import { computedExpandedClassName } from '../utils/expandUtil' ;
10
- import { TableProps } from '..' ;
10
+ import type { TableProps } from '..' ;
11
11
12
12
export interface BodyRowProps < RecordType > {
13
13
record : RecordType ;
@@ -22,6 +22,14 @@ export interface BodyRowProps<RecordType> {
22
22
scopeCellComponent : CustomizeComponent ;
23
23
indent ?: number ;
24
24
rowKey : React . Key ;
25
+ rowKeys : React . Key [ ] ;
26
+
27
+ // Expanded Row
28
+ expandedRowInfo ?: {
29
+ offset : number ;
30
+ colSpan : number ;
31
+ sticky : number ;
32
+ } ;
25
33
}
26
34
27
35
// ==================================================================================
@@ -33,6 +41,8 @@ export function getCellProps<RecordType>(
33
41
colIndex : number ,
34
42
indent : number ,
35
43
index : number ,
44
+ rowKeys : React . Key [ ] = [ ] ,
45
+ expandedRowOffset = 0 ,
36
46
) {
37
47
const {
38
48
record,
@@ -46,6 +56,8 @@ export function getCellProps<RecordType>(
46
56
expanded,
47
57
hasNestChildren,
48
58
onTriggerExpand,
59
+ expandable,
60
+ expandedKeys,
49
61
} = rowInfo ;
50
62
51
63
const key = columnsKey [ colIndex ] ;
@@ -71,16 +83,32 @@ export function getCellProps<RecordType>(
71
83
) ;
72
84
}
73
85
74
- let additionalCellProps : React . TdHTMLAttributes < HTMLElement > ;
75
- if ( column . onCell ) {
76
- additionalCellProps = column . onCell ( record , index ) ;
86
+ const additionalCellProps = column . onCell ?.( record , index ) || { } ;
87
+
88
+ // Expandable row has offset
89
+ if ( expandedRowOffset ) {
90
+ const { rowSpan = 1 } = additionalCellProps ;
91
+
92
+ // For expandable row with rowSpan,
93
+ // We should increase the rowSpan if the row is expanded
94
+ if ( expandable && rowSpan && colIndex < expandedRowOffset ) {
95
+ let currentRowSpan = rowSpan ;
96
+
97
+ for ( let i = index ; i < index + rowSpan ; i += 1 ) {
98
+ const rowKey = rowKeys [ i ] ;
99
+ if ( expandedKeys . has ( rowKey ) ) {
100
+ currentRowSpan += 1 ;
101
+ }
102
+ }
103
+ additionalCellProps . rowSpan = currentRowSpan ;
104
+ }
77
105
}
78
106
79
107
return {
80
108
key,
81
109
fixedInfo,
82
110
appendCellNode,
83
- additionalCellProps : additionalCellProps || { } ,
111
+ additionalCellProps : additionalCellProps ,
84
112
} ;
85
113
}
86
114
@@ -103,10 +131,12 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
103
131
index,
104
132
renderIndex,
105
133
rowKey,
134
+ rowKeys,
106
135
indent = 0 ,
107
136
rowComponent : RowComponent ,
108
137
cellComponent,
109
138
scopeCellComponent,
139
+ expandedRowInfo,
110
140
} = props ;
111
141
112
142
const rowInfo = useRowInfo ( record , rowKey , index , indent ) ;
@@ -164,6 +194,8 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
164
194
colIndex ,
165
195
indent ,
166
196
index ,
197
+ rowKeys ,
198
+ expandedRowInfo ?. offset ,
167
199
) ;
168
200
169
201
return (
@@ -207,8 +239,9 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
207
239
prefixCls = { prefixCls }
208
240
component = { RowComponent }
209
241
cellComponent = { cellComponent }
210
- colSpan = { flattenColumns . length }
242
+ colSpan = { expandedRowInfo ? expandedRowInfo . colSpan : flattenColumns . length }
211
243
isEmpty = { false }
244
+ stickyOffset = { expandedRowInfo ?. sticky }
212
245
>
213
246
{ expandContent }
214
247
</ ExpandedRow >
0 commit comments