@@ -66,6 +66,8 @@ export class DataTable extends React.Component<DataTableProps & WithStylesProps,
66
66
sortDirection : this . props . sortDirectionOverride ! ,
67
67
} ;
68
68
69
+ timeoutId : number = 0 ;
70
+
69
71
constructor ( props : DataTableProps & WithStylesProps ) {
70
72
super ( props ) ;
71
73
if ( this . props . dataTableRef ) {
@@ -114,10 +116,7 @@ export class DataTable extends React.Component<DataTableProps & WithStylesProps,
114
116
const { dynamicRowHeight, data, filterData, width, height, sortByCacheKey } = this . props ;
115
117
const { sortBy, sortDirection } = this . state ;
116
118
const dimensionsChanged = width !== prevProps . width || height !== prevProps . height ;
117
- const sortChanged =
118
- sortBy !== prevState . sortBy ||
119
- sortDirection !== prevState . sortDirection ||
120
- sortByCacheKey !== prevProps . sortByCacheKey ;
119
+ const sortChanged = sortByCacheKey !== prevProps . sortByCacheKey ;
121
120
const sortedData : IndexedParentRow [ ] = this . getData (
122
121
data ! ,
123
122
sortBy ,
@@ -134,20 +133,19 @@ export class DataTable extends React.Component<DataTableProps & WithStylesProps,
134
133
x . metadata . originalIndex !== oldFilteredData [ i ] . metadata . originalIndex ,
135
134
) ) ;
136
135
137
- if ( dynamicRowHeight && ( filteredDataChanged || dimensionsChanged || sortChanged ) ) {
138
- // We need to make sure the cache is cleared before React tries to re-render.
139
- window . setTimeout ( ( ) => {
140
- this . cache . clearAll ( ) ;
141
- this . forceUpdate ( ) ;
142
- } , 0 ) ;
143
- }
144
-
145
136
if ( this . props . data !== prevProps . data ) {
146
137
this . keys = getKeys ( this . props . keys ! , this . props . data ! ) ;
147
138
148
139
this . setState ( {
149
140
expandedRows : new Set ( ) ,
150
141
} ) ;
142
+ } else if ( dynamicRowHeight && ( filteredDataChanged || dimensionsChanged || sortChanged ) ) {
143
+ // We need to make sure the cache is cleared before React tries to re-render.
144
+ if ( this . timeoutId ) window . clearTimeout ( this . timeoutId ) ;
145
+ this . timeoutId = window . setTimeout ( ( ) => {
146
+ this . cache . clearAll ( ) ;
147
+ this . forceUpdate ( ) ;
148
+ } ) ;
151
149
}
152
150
}
153
151
@@ -224,10 +222,11 @@ export class DataTable extends React.Component<DataTableProps & WithStylesProps,
224
222
225
223
if ( dynamicRowHeight ) {
226
224
// We need to make sure the cache is cleared before React tries to re-render.
227
- window . setTimeout ( ( ) => {
225
+ if ( this . timeoutId ) window . clearTimeout ( this . timeoutId ) ;
226
+ this . timeoutId = window . setTimeout ( ( ) => {
228
227
this . cache . clearAll ( ) ;
229
228
this . forceUpdate ( ) ;
230
- } , 0 ) ;
229
+ } ) ;
231
230
}
232
231
} ;
233
232
0 commit comments