@@ -31,6 +31,8 @@ function Body<RecordType>(props: BodyProps<RecordType>) {
3131 expandedKeys,
3232 childrenColumnName,
3333 emptyNode,
34+ expandedRowOffset = 0 ,
35+ colWidths,
3436 } = useContext ( TableContext , [
3537 'prefixCls' ,
3638 'getComponent' ,
@@ -40,16 +42,42 @@ function Body<RecordType>(props: BodyProps<RecordType>) {
4042 'expandedKeys' ,
4143 'childrenColumnName' ,
4244 'emptyNode' ,
45+ 'expandedRowOffset' ,
46+ 'fixedInfoList' ,
47+ 'colWidths' ,
4348 ] ) ;
4449
45- const flattenData : { record : RecordType ; indent : number ; index : number } [ ] =
46- useFlattenRecords < RecordType > ( data , childrenColumnName , expandedKeys , getRowKey ) ;
50+ const flattenData = useFlattenRecords < RecordType > (
51+ data ,
52+ childrenColumnName ,
53+ expandedKeys ,
54+ getRowKey ,
55+ ) ;
56+ const rowKeys = React . useMemo ( ( ) => flattenData . map ( item => item . rowKey ) , [ flattenData ] ) ;
4757
4858 // =================== Performance ====================
4959 const perfRef = React . useRef < PerfRecord > ( {
5060 renderWithProps : false ,
5161 } ) ;
5262
63+ // ===================== Expanded =====================
64+ // `expandedRowOffset` data is same for all the rows.
65+ // Let's calc on Body side to save performance.
66+ const expandedRowInfo = React . useMemo ( ( ) => {
67+ const expandedColSpan = flattenColumns . length - expandedRowOffset ;
68+
69+ let expandedStickyStart = 0 ;
70+ for ( let i = 0 ; i < expandedRowOffset ; i += 1 ) {
71+ expandedStickyStart += colWidths [ i ] || 0 ;
72+ }
73+
74+ return {
75+ offset : expandedRowOffset ,
76+ colSpan : expandedColSpan ,
77+ sticky : expandedStickyStart ,
78+ } ;
79+ } , [ flattenColumns . length , expandedRowOffset , colWidths ] ) ;
80+
5381 // ====================== Render ======================
5482 const WrapperComponent = getComponent ( [ 'body' , 'wrapper' ] , 'tbody' ) ;
5583 const trComponent = getComponent ( [ 'body' , 'row' ] , 'tr' ) ;
@@ -59,21 +87,22 @@ function Body<RecordType>(props: BodyProps<RecordType>) {
5987 let rows : React . ReactNode ;
6088 if ( data . length ) {
6189 rows = flattenData . map ( ( item , idx ) => {
62- const { record, indent, index : renderIndex } = item ;
63-
64- const key = getRowKey ( record , idx ) ;
90+ const { record, indent, index : renderIndex , rowKey } = item ;
6591
6692 return (
6793 < BodyRow
68- key = { key }
69- rowKey = { key }
94+ key = { rowKey }
95+ rowKey = { rowKey }
96+ rowKeys = { rowKeys }
7097 record = { record }
7198 index = { idx }
7299 renderIndex = { renderIndex }
73100 rowComponent = { trComponent }
74101 cellComponent = { tdComponent }
75102 scopeCellComponent = { thComponent }
76103 indent = { indent }
104+ // Expanded row info
105+ expandedRowInfo = { expandedRowInfo }
77106 />
78107 ) ;
79108 } ) ;
0 commit comments