@@ -3,7 +3,7 @@ import React, { ReactNode } from 'react'
33import { ExpansionCell , icons , InlineFlexCell } from '../../common-views'
44import { ArtColumn } from '../../interfaces'
55import { internals } from '../../internals'
6- import { collectNodes , mergeCellProps } from '../../utils'
6+ import { collectNodes , mergeCellProps , upDataFirstCol } from '../../utils'
77import { always , flatMap } from '../../utils/others'
88import { TablePipeline } from '../pipeline'
99
@@ -100,7 +100,7 @@ export function rowDetail(opts: RowDetailFeatureOptions = {}) {
100100 onChangeOpenKeys ( [ ...openKeys , rowKey ] , rowKey , 'expand' )
101101 }
102102 }
103-
103+
104104 // 还原primaryKey
105105 const resetRow = ( row :any ) => {
106106 let key = row [ originKeySymbol ] ;
@@ -132,87 +132,86 @@ export function rowDetail(opts: RowDetailFeatureOptions = {}) {
132132 return columns
133133 }
134134 const columnFlatCount = collectNodes ( columns , 'leaf-only' ) . length
135- const [ firstCol , ...others ] = columns
136-
137- const render = ( value : any , row : any , rowIndex : number ) => {
138- if ( row [ rowDetailMetaKey ] ) {
139- return renderDetail ( resetRow ( row ) , rowIndex )
140- }
141-
142- const content = internals . safeRender ( firstCol , row , rowIndex )
143135
144- if ( ! hasDetail ( row , rowIndex ) ) {
145- return < InlineFlexCell style = { { marginLeft : textOffset } } > { content } </ InlineFlexCell >
146- }
136+ return upDataFirstCol ( columns , ( firstCol ) => {
147137
148- const rowKey = row [ primaryKey ]
149- const expanded = openKeySet . has ( rowKey )
150- const onClick = ( e : React . MouseEvent ) => {
151- if ( opts . stopClickEventPropagation ) {
152- e . stopPropagation ( )
138+ const render = ( value : any , row : any , rowIndex : number ) => {
139+ if ( row [ rowDetailMetaKey ] ) {
140+ return renderDetail ( resetRow ( row ) , rowIndex )
153141 }
154- toggle ( rowKey )
155- }
156-
157- const expandCls = expanded ? 'expanded' : 'collapsed'
158- return (
159- < ExpansionCell
160- className = { cx ( 'expansion-cell' , expandCls ) }
161- style = { { cursor : clickArea === 'content' ? 'pointer' : undefined } }
162- onClick = { clickArea === 'content' ? onClick : undefined }
163- >
164- < icons . CaretRight
165- style = { {
166- cursor : clickArea === 'icon' ? 'pointer' : undefined ,
167- marginLeft : indents . iconIndent ,
168- marginRight : indents . iconGap ,
169- } }
170- className = { cx ( 'expansion-icon' , expandCls ) }
171- onClick = { clickArea === 'icon' ? onClick : undefined }
172- />
173- { content }
174- </ ExpansionCell >
175- )
176- }
177-
178- const getCellProps = ( value : any , row : any , rowIndex : number ) => {
179- if ( row [ rowDetailMetaKey ] ) {
180- return {
181- style : {
182- '--cell-padding' : '0' ,
183- overflow : 'hidden' ,
184- ...opts . detailCellStyle ,
185- } as any ,
142+
143+ const content = internals . safeRender ( firstCol , row , rowIndex )
144+
145+ if ( ! hasDetail ( row , rowIndex ) ) {
146+ return < InlineFlexCell style = { { marginLeft : textOffset } } > { content } </ InlineFlexCell >
186147 }
187- }
188-
189- const prevProps = firstCol . getCellProps ?.( value , row , rowIndex )
190-
191- if ( ! hasDetail ( row , rowIndex ) ) {
192- return prevProps
193- }
194-
195- return mergeCellProps ( prevProps , {
196- onClick ( e ) {
148+
149+ const rowKey = row [ primaryKey ]
150+ const expanded = openKeySet . has ( rowKey )
151+ const onClick = ( e : React . MouseEvent ) => {
197152 if ( opts . stopClickEventPropagation ) {
198153 e . stopPropagation ( )
199154 }
200- toggle ( row [ primaryKey ] )
201- } ,
202- style : { cursor : 'pointer' } ,
203- } )
204- }
155+ toggle ( rowKey )
156+ }
157+
158+ const expandCls = expanded ? 'expanded' : 'collapsed'
159+ return (
160+ < ExpansionCell
161+ className = { cx ( 'expansion-cell' , expandCls ) }
162+ style = { { cursor : clickArea === 'content' ? 'pointer' : undefined } }
163+ onClick = { clickArea === 'content' ? onClick : undefined }
164+ >
165+ < icons . CaretRight
166+ style = { {
167+ cursor : clickArea === 'icon' ? 'pointer' : undefined ,
168+ marginLeft : indents . iconIndent ,
169+ marginRight : indents . iconGap ,
170+ } }
171+ className = { cx ( 'expansion-icon' , expandCls ) }
172+ onClick = { clickArea === 'icon' ? onClick : undefined }
173+ />
174+ { content }
175+ </ ExpansionCell >
176+ )
177+ }
178+
179+ const getCellProps = ( value : any , row : any , rowIndex : number ) => {
180+ if ( row [ rowDetailMetaKey ] ) {
181+ return {
182+ style : {
183+ '--cell-padding' : '0' ,
184+ overflow : 'hidden' ,
185+ ...opts . detailCellStyle ,
186+ } as any ,
187+ }
188+ }
189+
190+ const prevProps = firstCol . getCellProps ?.( value , row , rowIndex )
191+
192+ if ( ! hasDetail ( row , rowIndex ) ) {
193+ return prevProps
194+ }
195+
196+ return mergeCellProps ( prevProps , {
197+ onClick ( e ) {
198+ if ( opts . stopClickEventPropagation ) {
199+ e . stopPropagation ( )
200+ }
201+ toggle ( row [ primaryKey ] )
202+ } ,
203+ style : { cursor : 'pointer' } ,
204+ } )
205+ }
205206
206- return [
207- {
207+ return {
208208 ...firstCol ,
209209 title : (
210210 < div style = { { display : 'inline-block' , marginLeft : textOffset } } >
211211 { internals . safeRenderHeader ( firstCol ) }
212212 </ div >
213213 ) ,
214214 render,
215- // getCellProps: clickArea === 'cell' ? getCellProps : firstCol.getCellProps,
216215 getCellProps : ( value : any , row : any , rowIndex : number ) => {
217216 if ( row [ rowDetailMetaKey ] || clickArea === 'cell' ) {
218217 return getCellProps ( value , row , rowIndex ) ;
@@ -225,10 +224,9 @@ export function rowDetail(opts: RowDetailFeatureOptions = {}) {
225224 // detail 总是成一行
226225 return { top : rowIndex , bottom : rowIndex + 1 , left : 0 , right : columnFlatCount }
227226 }
228- } ,
229- } ,
230- ...others ,
231- ]
227+ }
228+ } as ArtColumn
229+ } )
232230 }
233231 }
234232}
0 commit comments