@@ -7,7 +7,7 @@ import useRowInfo from '../hooks/useRowInfo';
77import type { ColumnType , CustomizeComponent } from '../interface' ;
88import ExpandedRow from './ExpandedRow' ;
99import { computedExpandedClassName } from '../utils/expandUtil' ;
10- import { TableProps } from '..' ;
10+ import type { TableProps } from '..' ;
1111
1212export interface BodyRowProps < RecordType > {
1313 record : RecordType ;
@@ -22,6 +22,14 @@ export interface BodyRowProps<RecordType> {
2222 scopeCellComponent : CustomizeComponent ;
2323 indent ?: number ;
2424 rowKey : React . Key ;
25+ rowKeys : React . Key [ ] ;
26+
27+ // Expanded Row
28+ expandedRowInfo ?: {
29+ offset : number ;
30+ colSpan : number ;
31+ sticky : number ;
32+ } ;
2533}
2634
2735// ==================================================================================
@@ -33,6 +41,8 @@ export function getCellProps<RecordType>(
3341 colIndex : number ,
3442 indent : number ,
3543 index : number ,
44+ rowKeys : React . Key [ ] = [ ] ,
45+ expandedRowOffset = 0 ,
3646) {
3747 const {
3848 record,
@@ -46,6 +56,8 @@ export function getCellProps<RecordType>(
4656 expanded,
4757 hasNestChildren,
4858 onTriggerExpand,
59+ expandable,
60+ expandedKeys,
4961 } = rowInfo ;
5062
5163 const key = columnsKey [ colIndex ] ;
@@ -71,16 +83,32 @@ export function getCellProps<RecordType>(
7183 ) ;
7284 }
7385
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+ }
77105 }
78106
79107 return {
80108 key,
81109 fixedInfo,
82110 appendCellNode,
83- additionalCellProps : additionalCellProps || { } ,
111+ additionalCellProps : additionalCellProps ,
84112 } ;
85113}
86114
@@ -103,10 +131,12 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
103131 index,
104132 renderIndex,
105133 rowKey,
134+ rowKeys,
106135 indent = 0 ,
107136 rowComponent : RowComponent ,
108137 cellComponent,
109138 scopeCellComponent,
139+ expandedRowInfo,
110140 } = props ;
111141
112142 const rowInfo = useRowInfo ( record , rowKey , index , indent ) ;
@@ -164,6 +194,8 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
164194 colIndex ,
165195 indent ,
166196 index ,
197+ rowKeys ,
198+ expandedRowInfo ?. offset ,
167199 ) ;
168200
169201 return (
@@ -207,8 +239,9 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
207239 prefixCls = { prefixCls }
208240 component = { RowComponent }
209241 cellComponent = { cellComponent }
210- colSpan = { flattenColumns . length }
242+ colSpan = { expandedRowInfo ? expandedRowInfo . colSpan : flattenColumns . length }
211243 isEmpty = { false }
244+ stickyOffset = { expandedRowInfo ?. sticky }
212245 >
213246 { expandContent }
214247 </ ExpandedRow >
0 commit comments