Skip to content
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

Add rowKeyGetter to Table component. #117

Merged
merged 2 commits into from
Feb 14, 2017
Merged

Add rowKeyGetter to Table component. #117

merged 2 commits into from
Feb 14, 2017

Conversation

conorbranagan
Copy link
Contributor

Description

If you set a rowKeyGetter prop for the Table component then the key value for each FixedDataTableRow can be overridden based on the rowIndex.

Motivation and Context

This is particularly useful when using CSS animations where you only want transitions to animate if the data source for the row remains the same. So in this case your key getter might instead send the key of the data object.

See also from the original repo: facebookarchive/fixed-data-table#353

How Has This Been Tested?

Tested in a local project using a % progress-bar style viz. Once we use the object key instead of the default we can see that animations only happen when a data changes for a row that has remained in the same location.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

@@ -142,7 +144,7 @@ var FixedDataTableBufferedRows = React.createClass({

this._staticRowArray[i] =
<FixedDataTableRow
key={i}
key={rowKeyGetter(rowIndex)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wcjordan Do you think there is any risk in this change? I remember there was discussion about indexing this by rowIndex instead of its array order in the past

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're thinking of PR #85 regarding recycling column keys.

I think this is fine, and may be good if we think rowIndex is more likely to allow row recycling than array index. We should sanity check though and ensure this doesn't cause any funkiness with image loading or anything like that.

If we want to be really conservative, we can also make the rowKeyGetter take 2 params, rowIndex and arrayIndex and have the default just return arrayIndex.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to make the change to the rowKeyGetter? Happy to do it if that's blocking a merge on this. Thanks!

Copy link
Contributor

@KamranAsif KamranAsif Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@conorbranagan Sorry for the delayed response, got busy with some work and forgot about this PR.
Can we just do something like

var rowKey = props.rowKeyGetter ? props.rowKeyGetter(rowIndex) : i

passing array index seems weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, thanks for looking. Updated the PR

If you set a rowKeyGetter then the `key` value for each FixedDataTableRow can
be overridden based on the rowIndex.

This is particularly useful when using CSS animations where you only want
transitions to animate if the data source remains the same.

See also: facebookarchive/fixed-data-table#353
@KamranAsif
Copy link
Contributor

LGTM

@KamranAsif KamranAsif merged commit 76ee979 into schrodinger:master Feb 14, 2017
@conorbranagan conorbranagan deleted the add-rowKeyGetter branch February 15, 2017 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants