@@ -271,7 +271,7 @@ class Table extends React.Component {
271
271
}
272
272
273
273
getTBody ( columns , data , sortBy , itemHeight ) {
274
- const buildRowOptions = this . props . buildRowOptions ;
274
+ const { buildRowOptions, virtualizeDataThreshold } = this . props ;
275
275
let childToMeasure ;
276
276
277
277
if ( itemHeight === 0 && data . length ) {
@@ -290,13 +290,32 @@ class Table extends React.Component {
290
290
return < tbody > { this . getEmptyRowCell ( columns ) } </ tbody > ;
291
291
}
292
292
293
+ const sortedData = sortData ( columns , data , sortBy ) ;
294
+
295
+ if ( data . length < virtualizeDataThreshold ) {
296
+ // Do not use virtual list for "small" data sets
297
+ return (
298
+ < tbody >
299
+ { sortedData . map ( ( item , index ) => {
300
+ return this . getRowCells (
301
+ columns ,
302
+ sortBy ,
303
+ buildRowOptions ,
304
+ item ,
305
+ index
306
+ ) ;
307
+ } ) }
308
+ </ tbody >
309
+ ) ;
310
+ }
311
+
293
312
return (
294
313
< VirtualList
295
314
className = "table-virtual-list"
296
315
container = { this . container }
297
316
itemBuffer = { 70 }
298
317
itemHeight = { itemHeight }
299
- items = { sortData ( columns , data , sortBy ) }
318
+ items = { sortedData }
300
319
renderBufferItem = { this . getBufferItem . bind ( this , columns ) }
301
320
renderItem = { this . getRowCells . bind (
302
321
this ,
@@ -336,7 +355,8 @@ Table.defaultProps = {
336
355
return { } ;
337
356
} ,
338
357
sortBy : { } ,
339
- emptyMessage : "No data"
358
+ emptyMessage : "No data" ,
359
+ virtualizeDataThreshold : 1000
340
360
} ;
341
361
342
362
Table . propTypes = {
@@ -405,7 +425,10 @@ Table.propTypes = {
405
425
sortBy : PropTypes . shape ( {
406
426
order : PropTypes . oneOf ( [ "asc" , "desc" ] ) ,
407
427
prop : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . number ] )
408
- } )
428
+ } ) ,
429
+
430
+ // Optional cutoff at which to begin rendering a virtualized list
431
+ virtualizeDataThreshold : PropTypes . number
409
432
} ;
410
433
411
434
module . exports = Table ;
0 commit comments