@@ -19,6 +19,7 @@ import {
1919 renderElement ,
2020 normalizeColumns ,
2121 getScrollbarSize as defaultGetScrollbarSize ,
22+ getEstimatedTotalRowsHeight ,
2223 isObjectEqual ,
2324 callOrReturn ,
2425 hasChildren ,
@@ -120,6 +121,7 @@ class BaseTable extends React.PureComponent {
120121 this . _mainRowHeightMap = { } ;
121122 this . _leftRowHeightMap = { } ;
122123 this . _rightRowHeightMap = { } ;
124+ this . _getEstimatedTotalRowsHeight = memoize ( getEstimatedTotalRowsHeight ) ;
123125 this . _getRowHeight = this . _getRowHeight . bind ( this ) ;
124126 this . _updateRowHeights = debounce ( ( ) => {
125127 this . _isResetting = true ;
@@ -185,7 +187,9 @@ class BaseTable extends React.PureComponent {
185187 const { rowHeight, estimatedRowHeight } = this . props ;
186188
187189 if ( estimatedRowHeight ) {
188- return this . table ? this . table . getTotalRowsHeight ( ) : this . _data . length * estimatedRowHeight ;
190+ return this . table
191+ ? this . table . getTotalRowsHeight ( )
192+ : this . _getEstimatedTotalRowsHeight ( this . _data , estimatedRowHeight ) ;
189193 }
190194 return this . _data . length * rowHeight ;
191195 }
@@ -716,7 +720,7 @@ class BaseTable extends React.PureComponent {
716720 [ `${ classPrefix } --has-frozen-rows` ] : frozenData . length > 0 ,
717721 [ `${ classPrefix } --has-frozen-columns` ] : this . columnManager . hasFrozenColumns ( ) ,
718722 [ `${ classPrefix } --disabled` ] : disabled ,
719- [ `${ classPrefix } --dynamic` ] : estimatedRowHeight > 0 ,
723+ [ `${ classPrefix } --dynamic` ] : ! ! estimatedRowHeight ,
720724 } ) ;
721725 return (
722726 < div ref = { this . _setContainerRef } className = { cls } style = { containerStyle } >
@@ -785,7 +789,10 @@ class BaseTable extends React.PureComponent {
785789 // for dynamic row height
786790 _getRowHeight ( rowIndex ) {
787791 const { estimatedRowHeight, rowKey } = this . props ;
788- return this . _rowHeightMap [ this . _data [ rowIndex ] [ rowKey ] ] || estimatedRowHeight ;
792+ return (
793+ this . _rowHeightMap [ this . _data [ rowIndex ] [ rowKey ] ] ||
794+ callOrReturn ( estimatedRowHeight , { rowData : this . _data [ rowIndex ] , rowIndex } )
795+ ) ;
789796 }
790797
791798 _getIsResetting ( ) {
@@ -1103,8 +1110,9 @@ BaseTable.propTypes = {
11031110 rowHeight : PropTypes . number ,
11041111 /**
11051112 * Estimated row height, the real height will be measure dynamically according to the content
1113+ * The callback is of the shape of `({ rowData, rowIndex }) => number`
11061114 */
1107- estimatedRowHeight : PropTypes . number ,
1115+ estimatedRowHeight : PropTypes . oneOfType ( [ PropTypes . number , PropTypes . func ] ) ,
11081116 /**
11091117 * The height of the table header, set to 0 to hide the header, could be an array to render multi headers.
11101118 */
0 commit comments