11import React from 'react' ;
2+ import ReactDOM from 'react-dom' ;
23import PropTypes from 'prop-types' ;
34import { connect } from 'mini-store' ;
45import TableCell from './TableCell' ;
@@ -36,6 +37,7 @@ class TableRow extends React.Component {
3637 ] ) ,
3738 renderExpandIcon : PropTypes . func ,
3839 renderExpandIconCell : PropTypes . func ,
40+ components : PropTypes . any ,
3941 }
4042
4143 static defaultProps = {
@@ -58,12 +60,24 @@ class TableRow extends React.Component {
5860 this . shouldRender = props . visible ;
5961 }
6062
63+ componentDidMount ( ) {
64+ if ( this . shouldRender ) {
65+ this . saveRowRef ( ) ;
66+ }
67+ }
68+
6169 componentWillReceiveProps ( nextProps ) {
6270 if ( this . props . visible || ( ! this . props . visible && nextProps . visible ) ) {
6371 this . shouldRender = true ;
6472 }
6573 }
6674
75+ componentDidUpdate ( ) {
76+ if ( this . shouldRender && ! this . rowRef ) {
77+ this . saveRowRef ( ) ;
78+ }
79+ }
80+
6781 onRowClick = ( event ) => {
6882 const { record, index, onRowClick } = this . props ;
6983 onRowClick ( record , index , event ) ;
@@ -99,12 +113,11 @@ class TableRow extends React.Component {
99113 store . setState ( { expandedRowsHeight } ) ;
100114 }
101115
102- saveRowRef = ( node ) => {
103- this . rowRef = node ;
104- if ( node ) {
105- if ( ! this . props . fixed ) {
106- this . setHeight ( ) ;
107- }
116+ saveRowRef ( ) {
117+ this . rowRef = ReactDOM . findDOMNode ( this ) ;
118+
119+ if ( ! this . props . fixed ) {
120+ this . setHeight ( ) ;
108121 }
109122 }
110123
@@ -123,11 +136,20 @@ class TableRow extends React.Component {
123136 visible,
124137 height,
125138 hovered,
139+ components,
126140 hasExpandIcon,
127141 renderExpandIcon,
128142 renderExpandIconCell,
129143 } = this . props ;
130144
145+ let BodyRow = 'tr' ;
146+ let BodyCell = 'td' ;
147+
148+ if ( components && components . body ) {
149+ BodyRow = components . body . row || BodyRow ;
150+ BodyCell = components . body . cell || BodyCell ;
151+ }
152+
131153 let { className } = this . props ;
132154
133155 if ( hovered ) {
@@ -149,6 +171,7 @@ class TableRow extends React.Component {
149171 column = { columns [ i ] }
150172 key = { columns [ i ] . key || columns [ i ] . dataIndex }
151173 expandIcon = { hasExpandIcon ( i ) && renderExpandIcon ( ) }
174+ component = { BodyCell }
152175 />
153176 ) ;
154177 }
@@ -163,8 +186,7 @@ class TableRow extends React.Component {
163186 `${ prefixCls } ${ className } ${ prefixCls } -level-${ indent } ` . trim ( ) ;
164187
165188 return (
166- < tr
167- ref = { this . saveRowRef }
189+ < BodyRow
168190 onClick = { this . onRowClick }
169191 onDoubleClick = { this . onRowDoubleClick }
170192 onMouseEnter = { this . onMouseEnter }
@@ -174,7 +196,7 @@ class TableRow extends React.Component {
174196 style = { style }
175197 >
176198 { cells }
177- </ tr >
199+ </ BodyRow >
178200 ) ;
179201 }
180202}
0 commit comments