@@ -4,7 +4,7 @@ import Cell from '../Cell';
4
4
import { responseImmutable } from '../context/TableContext' ;
5
5
import devRenderTimes from '../hooks/useRenderTimes' ;
6
6
import useRowInfo from '../hooks/useRowInfo' ;
7
- import type { ColumnType , CustomizeComponent , ExpandableConfig } from '../interface' ;
7
+ import type { ColumnType , CustomizeComponent } from '../interface' ;
8
8
import ExpandedRow from './ExpandedRow' ;
9
9
import { computedExpandedClassName } from '../utils/expandUtil' ;
10
10
import type { TableProps } from '..' ;
@@ -23,7 +23,6 @@ export interface BodyRowProps<RecordType> {
23
23
indent ?: number ;
24
24
rowKey : React . Key ;
25
25
rowKeys : React . Key [ ] ;
26
- expandedRowOffset ?: ExpandableConfig < RecordType > [ 'expandedRowOffset' ] ;
27
26
}
28
27
29
28
// ==================================================================================
@@ -104,9 +103,31 @@ export function getCellProps<RecordType>(
104
103
} ;
105
104
}
106
105
107
- // ==================================================================================
108
- // == getCellProps ==
109
- // ==================================================================================
106
+ const getOffsetData = (
107
+ columnsData : {
108
+ column : ColumnType < any > ;
109
+ cell : { additionalCellProps : React . TdHTMLAttributes < HTMLElement > } ;
110
+ } [ ] ,
111
+ ) => {
112
+ let offsetWidth = 0 ;
113
+ let offsetColumn = 0 ;
114
+ let isRowSpanEnd = false ;
115
+ columnsData . forEach ( item => {
116
+ if ( ! isRowSpanEnd ) {
117
+ const { column, cell } = item ;
118
+ if ( cell . additionalCellProps . rowSpan !== undefined ) {
119
+ offsetColumn += 1 ;
120
+ if ( typeof column . width === 'number' ) {
121
+ offsetWidth = offsetWidth + ( column . width ?? 0 ) ;
122
+ }
123
+ } else {
124
+ isRowSpanEnd = true ;
125
+ }
126
+ }
127
+ } ) ;
128
+ return { offsetWidth, offsetColumn } ;
129
+ } ;
130
+
110
131
function BodyRow < RecordType extends { children ?: readonly RecordType [ ] } > (
111
132
props : BodyRowProps < RecordType > ,
112
133
) {
@@ -127,7 +148,6 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
127
148
rowComponent : RowComponent ,
128
149
cellComponent,
129
150
scopeCellComponent,
130
- expandedRowOffset = 0 ,
131
151
rowKeys,
132
152
} = props ;
133
153
@@ -157,6 +177,17 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
157
177
// 此时如果 level > 1 则说明是 expandedRow, 一样需要附加 computedExpandedRowClassName
158
178
const expandedClsName = computedExpandedClassName ( expandedRowClassName , record , index , indent ) ;
159
179
180
+ const { columnsData, offsetData } = React . useMemo ( ( ) => {
181
+ // eslint-disable-next-line @typescript-eslint/no-shadow
182
+ const columnsData = flattenColumns . map ( ( column : ColumnType < RecordType > , colIndex ) => {
183
+ const cell = getCellProps ( rowInfo , column , colIndex , indent , index , rowKeys ) ;
184
+ return { column, cell } ;
185
+ } ) ;
186
+ // eslint-disable-next-line @typescript-eslint/no-shadow
187
+ const offsetData = getOffsetData ( columnsData ) ;
188
+ return { columnsData, offsetData } ;
189
+ } , [ flattenColumns , indent , index , rowInfo , rowKeys ] ) ;
190
+
160
191
// ======================== Base tr row ========================
161
192
const baseRowNode = (
162
193
< RowComponent
@@ -178,17 +209,11 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
178
209
...styles . row ,
179
210
} }
180
211
>
181
- { flattenColumns . map ( ( column : ColumnType < RecordType > , colIndex ) => {
212
+ { columnsData . map ( item => {
213
+ const { column, cell } = item ;
182
214
const { render, dataIndex, className : columnClassName } = column ;
183
215
184
- const { key, fixedInfo, appendCellNode, additionalCellProps } = getCellProps (
185
- rowInfo ,
186
- column ,
187
- colIndex ,
188
- indent ,
189
- index ,
190
- rowKeys ,
191
- ) ;
216
+ const { key, fixedInfo, appendCellNode, additionalCellProps } = cell ;
192
217
193
218
return (
194
219
< Cell < RecordType >
@@ -220,14 +245,6 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
220
245
if ( rowSupportExpand && ( expandedRef . current || expanded ) ) {
221
246
const expandContent = expandedRowRender ( record , index , indent + 1 , expanded ) ;
222
247
223
- const offsetColumns = flattenColumns . filter ( ( _ , idx ) => idx < expandedRowOffset ) ;
224
- let offsetWidth = 0 ;
225
- offsetColumns . forEach ( item => {
226
- if ( typeof item . width === 'number' ) {
227
- offsetWidth = offsetWidth + ( item . width ?? 0 ) ;
228
- }
229
- } ) ;
230
-
231
248
expandRowNode = (
232
249
< ExpandedRow
233
250
expanded = { expanded }
@@ -239,8 +256,8 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
239
256
prefixCls = { prefixCls }
240
257
component = { RowComponent }
241
258
cellComponent = { cellComponent }
242
- offsetWidth = { offsetWidth }
243
- colSpan = { flattenColumns . length - expandedRowOffset }
259
+ offsetWidth = { offsetData . offsetWidth }
260
+ colSpan = { flattenColumns . length - offsetData . offsetColumn }
244
261
isEmpty = { false }
245
262
>
246
263
{ expandContent }
0 commit comments