@@ -31,6 +31,8 @@ function Body<RecordType>(props: BodyProps<RecordType>) {
31
31
expandedKeys,
32
32
childrenColumnName,
33
33
emptyNode,
34
+ expandedRowOffset = 0 ,
35
+ colWidths,
34
36
} = useContext ( TableContext , [
35
37
'prefixCls' ,
36
38
'getComponent' ,
@@ -40,16 +42,42 @@ function Body<RecordType>(props: BodyProps<RecordType>) {
40
42
'expandedKeys' ,
41
43
'childrenColumnName' ,
42
44
'emptyNode' ,
45
+ 'expandedRowOffset' ,
46
+ 'fixedInfoList' ,
47
+ 'colWidths' ,
43
48
] ) ;
44
49
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 ] ) ;
47
57
48
58
// =================== Performance ====================
49
59
const perfRef = React . useRef < PerfRecord > ( {
50
60
renderWithProps : false ,
51
61
} ) ;
52
62
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
+
53
81
// ====================== Render ======================
54
82
const WrapperComponent = getComponent ( [ 'body' , 'wrapper' ] , 'tbody' ) ;
55
83
const trComponent = getComponent ( [ 'body' , 'row' ] , 'tr' ) ;
@@ -59,21 +87,22 @@ function Body<RecordType>(props: BodyProps<RecordType>) {
59
87
let rows : React . ReactNode ;
60
88
if ( data . length ) {
61
89
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 ;
65
91
66
92
return (
67
93
< BodyRow
68
- key = { key }
69
- rowKey = { key }
94
+ key = { rowKey }
95
+ rowKey = { rowKey }
96
+ rowKeys = { rowKeys }
70
97
record = { record }
71
98
index = { idx }
72
99
renderIndex = { renderIndex }
73
100
rowComponent = { trComponent }
74
101
cellComponent = { tdComponent }
75
102
scopeCellComponent = { thComponent }
76
103
indent = { indent }
104
+ // Expanded row info
105
+ expandedRowInfo = { expandedRowInfo }
77
106
/>
78
107
) ;
79
108
} ) ;
0 commit comments