@@ -4,7 +4,7 @@ import Cell from '../Cell';
44import { responseImmutable } from '../context/TableContext' ;
55import devRenderTimes from '../hooks/useRenderTimes' ;
66import useRowInfo from '../hooks/useRowInfo' ;
7- import type { ColumnType , CustomizeComponent , ExpandableConfig } from '../interface' ;
7+ import type { ColumnType , CustomizeComponent } from '../interface' ;
88import ExpandedRow from './ExpandedRow' ;
99import { computedExpandedClassName } from '../utils/expandUtil' ;
1010import type { TableProps } from '..' ;
@@ -23,7 +23,6 @@ export interface BodyRowProps<RecordType> {
2323 indent ?: number ;
2424 rowKey : React . Key ;
2525 rowKeys : React . Key [ ] ;
26- expandedRowOffset ?: ExpandableConfig < RecordType > [ 'expandedRowOffset' ] ;
2726}
2827
2928// ==================================================================================
@@ -104,9 +103,31 @@ export function getCellProps<RecordType>(
104103 } ;
105104}
106105
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+
110131function BodyRow < RecordType extends { children ?: readonly RecordType [ ] } > (
111132 props : BodyRowProps < RecordType > ,
112133) {
@@ -127,7 +148,6 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
127148 rowComponent : RowComponent ,
128149 cellComponent,
129150 scopeCellComponent,
130- expandedRowOffset = 0 ,
131151 rowKeys,
132152 } = props ;
133153
@@ -157,6 +177,17 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
157177 // 此时如果 level > 1 则说明是 expandedRow, 一样需要附加 computedExpandedRowClassName
158178 const expandedClsName = computedExpandedClassName ( expandedRowClassName , record , index , indent ) ;
159179
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+
160191 // ======================== Base tr row ========================
161192 const baseRowNode = (
162193 < RowComponent
@@ -178,17 +209,11 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
178209 ...styles . row ,
179210 } }
180211 >
181- { flattenColumns . map ( ( column : ColumnType < RecordType > , colIndex ) => {
212+ { columnsData . map ( item => {
213+ const { column, cell } = item ;
182214 const { render, dataIndex, className : columnClassName } = column ;
183215
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 ;
192217
193218 return (
194219 < Cell < RecordType >
@@ -220,14 +245,6 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
220245 if ( rowSupportExpand && ( expandedRef . current || expanded ) ) {
221246 const expandContent = expandedRowRender ( record , index , indent + 1 , expanded ) ;
222247
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-
231248 expandRowNode = (
232249 < ExpandedRow
233250 expanded = { expanded }
@@ -239,8 +256,8 @@ function BodyRow<RecordType extends { children?: readonly RecordType[] }>(
239256 prefixCls = { prefixCls }
240257 component = { RowComponent }
241258 cellComponent = { cellComponent }
242- offsetWidth = { offsetWidth }
243- colSpan = { flattenColumns . length - expandedRowOffset }
259+ offsetWidth = { offsetData . offsetWidth }
260+ colSpan = { flattenColumns . length - offsetData . offsetColumn }
244261 isEmpty = { false }
245262 >
246263 { expandContent }
0 commit comments