-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved performance on Table with a lot of columns (> 150) #942
Changes from 2 commits
2c2c17b
f5e598b
c707db6
76b17ae
8529620
720588c
7e961d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
/** @flow */ | ||
|
||
import type {CellPosition} from '../Grid'; | ||
// import type {CellPosition} from '../Grid'; | ||
|
||
import cn from 'classnames'; | ||
import Column from './Column'; | ||
import PropTypes from 'prop-types'; | ||
import React, {PureComponent} from 'react'; | ||
import {findDOMNode} from 'react-dom'; | ||
import Grid, {accessibilityOverscanIndicesGetter} from '../Grid'; | ||
import type {CellPosition} from '../Grid'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove newline |
||
import defaultRowRenderer from './defaultRowRenderer'; | ||
import defaultHeaderRowRenderer from './defaultHeaderRowRenderer'; | ||
import SortDirection from './SortDirection'; | ||
|
@@ -426,6 +428,7 @@ export default class Table extends PureComponent { | |
className, | ||
columnData, | ||
dataKey, | ||
title, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Alpha sort prop-lists like this 😄 |
||
id, | ||
} = column.props; | ||
|
||
|
@@ -443,23 +446,21 @@ export default class Table extends PureComponent { | |
|
||
const style = this._cachedColumnStyles[columnIndex]; | ||
|
||
const title = typeof renderedCell === 'string' ? renderedCell : null; | ||
const colTitle = title ? title : (typeof renderedCell === 'string' ? renderedCell : null); | ||
|
||
const a11yProps = { | ||
const columnProps = { | ||
role: 'gridcell', | ||
'aria-describedby': id || undefined, | ||
key: "Row" + rowIndex + "-" + "Col" + columnIndex, | ||
className: cn('ReactVirtualized__Table__rowColumn', className), | ||
style: style, | ||
title: colTitle, | ||
}; | ||
|
||
if (id) { | ||
a11yProps['aria-describedby'] = id; | ||
} | ||
|
||
|
||
return ( | ||
<div | ||
{...a11yProps} | ||
key={`Row${rowIndex}-Col${columnIndex}`} | ||
className={cn('ReactVirtualized__Table__rowColumn', className)} | ||
style={style} | ||
title={title}> | ||
{...columnProps} | ||
> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the crux of this fix is to avoid generating sub-optimal I'd suggest adding a comment about why it's important not to mix inline props and spread props. |
||
{renderedCell} | ||
</div> | ||
); | ||
|
@@ -480,6 +481,7 @@ export default class Table extends PureComponent { | |
headerRenderer, | ||
id, | ||
label, | ||
title, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another props-sort nit |
||
columnData, | ||
defaultSortDirection, | ||
} = column.props; | ||
|
@@ -507,10 +509,10 @@ export default class Table extends PureComponent { | |
sortDirection, | ||
}); | ||
|
||
const a11yProps = { | ||
role: 'columnheader', | ||
}; | ||
|
||
|
||
let chOnClick, cOnKeyDown, chTabIndex, ariaSort, ariaLabel; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does "ch0n" and "c0n" and "ch" mean? RV doesn't have an official styleguide, but if it did- "avoid abbreviated variable names" would be one of the first things I'd write. Please rename these. |
||
|
||
if (sortEnabled || onHeaderClick) { | ||
// If this is a sortable header, clicking it should update the table data's sorting. | ||
const isFirstTimeSort = sortBy !== dataKey; | ||
|
@@ -523,7 +525,7 @@ export default class Table extends PureComponent { | |
? SortDirection.ASC | ||
: SortDirection.DESC; | ||
|
||
const onClick = event => { | ||
const onClick = event => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: trailing whitespace |
||
sortEnabled && | ||
sort({ | ||
sortBy: dataKey, | ||
|
@@ -538,27 +540,33 @@ export default class Table extends PureComponent { | |
} | ||
}; | ||
|
||
a11yProps['aria-label'] = column.props['aria-label'] || label || dataKey; | ||
a11yProps.tabIndex = 0; | ||
a11yProps.onClick = onClick; | ||
a11yProps.onKeyDown = onKeyDown; | ||
ariaLabel = column.props['aria-label'] || label || dataKey; | ||
chTabIndex = 0; | ||
chOnClick = onClick; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move these values to object literal? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind. Didn't see condition |
||
chOnKeyDown = onKeyDown; | ||
} | ||
|
||
if (sortBy === dataKey) { | ||
a11yProps['aria-sort'] = | ||
sortDirection === SortDirection.ASC ? 'ascending' : 'descending'; | ||
ariaSort = sortDirection === SortDirection.ASC ? 'ascending' : 'descending'; | ||
} | ||
|
||
if (id) { | ||
a11yProps.id = id; | ||
} | ||
const colHeaderProps = { | ||
id: id || undefined, | ||
role: 'columnheader', | ||
'aria-label': ariaLabel, | ||
'aria-sort': ariaSort, | ||
tabIndex: chTabIndex, | ||
onClick: chOnClick, | ||
onKeyDown: chOnKeyDown, | ||
key: "Header-Col" + index, | ||
className: classNames, | ||
style: style, | ||
title: title || null | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same move and rename to headerProps |
||
return ( | ||
<div | ||
{...a11yProps} | ||
key={`Header-Col${index}`} | ||
className={classNames} | ||
style={style}> | ||
{...colHeaderProps}> | ||
{renderedHeader} | ||
</div> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move it back please