-
-
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 all 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ import PropTypes from 'prop-types'; | |
import React, {PureComponent} from 'react'; | ||
import {findDOMNode} from 'react-dom'; | ||
import Grid, {accessibilityOverscanIndicesGetter} from '../Grid'; | ||
|
||
import defaultRowRenderer from './defaultRowRenderer'; | ||
import defaultHeaderRowRenderer from './defaultHeaderRowRenderer'; | ||
import SortDirection from './SortDirection'; | ||
|
@@ -426,6 +427,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 +445,24 @@ export default class Table extends PureComponent { | |
|
||
const style = this._cachedColumnStyles[columnIndex]; | ||
|
||
const title = typeof renderedCell === 'string' ? renderedCell : null; | ||
const columnTitle = 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: columnTitle, | ||
}; | ||
|
||
if (id) { | ||
a11yProps['aria-describedby'] = id; | ||
} | ||
|
||
|
||
// NOTE: is important to NOT mixin inline property and spread properties, | ||
// since internally REACT clone property object to adds inline property | ||
// and slow down performances | ||
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. The wording of this comment (and the one below) confuse me. I don't think this has anything to do with "React internals" (unless I'm misunderstanding something). I believe this change is being made to avoid the overhead added by the Before this change: return _react2.default.createElement(
'div',
(0, _extends3.default)({}, a11yProps, {
key: 'Row' + rowIndex + '-Col' + columnIndex,
className: (0, _classnames2.default)('ReactVirtualized__Table__rowColumn', className),
style: style,
title: title }),
renderedCell
); After this change: return (
<div
{...columnProps}
>
{renderedCell}
</div>
); 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. That being said, I'm happy to update the wording of the comment myself, so don't worry about it. 😄 |
||
return ( | ||
<div | ||
{...a11yProps} | ||
key={`Row${rowIndex}-Col${columnIndex}`} | ||
className={cn('ReactVirtualized__Table__rowColumn', className)} | ||
style={style} | ||
title={title}> | ||
{...columnProps} | ||
> | ||
{renderedCell} | ||
</div> | ||
); | ||
|
@@ -480,6 +483,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 +511,10 @@ export default class Table extends PureComponent { | |
sortDirection, | ||
}); | ||
|
||
const a11yProps = { | ||
role: 'columnheader', | ||
}; | ||
|
||
|
||
let headerOnClick, headerOnKeyDown, headerTabIndex, headerAriaSort, headerAriaLabel; | ||
|
||
if (sortEnabled || onHeaderClick) { | ||
// If this is a sortable header, clicking it should update the table data's sorting. | ||
const isFirstTimeSort = sortBy !== dataKey; | ||
|
@@ -538,27 +542,36 @@ export default class Table extends PureComponent { | |
} | ||
}; | ||
|
||
a11yProps['aria-label'] = column.props['aria-label'] || label || dataKey; | ||
a11yProps.tabIndex = 0; | ||
a11yProps.onClick = onClick; | ||
a11yProps.onKeyDown = onKeyDown; | ||
headerAriaLabel = column.props['aria-label'] || label || dataKey; | ||
headerTabIndex = 0; | ||
headerOnClick = onClick; | ||
headerOnKeyDown = onKeyDown; | ||
} | ||
|
||
if (sortBy === dataKey) { | ||
a11yProps['aria-sort'] = | ||
sortDirection === SortDirection.ASC ? 'ascending' : 'descending'; | ||
headerAriaSort = sortDirection === SortDirection.ASC ? 'ascending' : 'descending'; | ||
} | ||
|
||
if (id) { | ||
a11yProps.id = id; | ||
} | ||
const headerProps = { | ||
id: id || undefined, | ||
role: 'columnheader', | ||
'aria-label': headerAriaLabel, | ||
'aria-sort': headerAriaSort, | ||
tabIndex: headerTabIndex, | ||
onClick: headerOnClick, | ||
onKeyDown: headerOnKeyDown, | ||
key: "Header-Col" + index, | ||
className: classNames, | ||
style: style, | ||
title: title || null | ||
}; | ||
|
||
// NOTE: is important to NOT mixin inline property and spread properties, | ||
// since internally REACT clone property object to adds inline property | ||
// and slow down performances | ||
return ( | ||
<div | ||
{...a11yProps} | ||
key={`Header-Col${index}`} | ||
className={classNames} | ||
style={style}> | ||
{...headerProps}> | ||
{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.
remove newline