Skip to content

Commit 76ee979

Browse files
conorbranaganKamranAsif
authored andcommitted
Add rowKeyGetter to Table component. (schrodinger#117)
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
1 parent de02f1d commit 76ee979

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

docs/api-v0.5/TableAPI.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ To get any additional CSS classes that should be added to a row,
146146
type: `func`
147147

148148

149+
### `rowKeyGetter`
150+
151+
If specified, `rowKeyGetter(index)` is called for each row and the
152+
returned value overrides `key` for the particular row.
153+
154+
type: `func`
155+
156+
149157
### `groupHeaderHeight`
150158

151159
Pixel height of the column group header.

src/FixedDataTable.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ var FixedDataTable = React.createClass({
187187
*/
188188
rowClassNameGetter: PropTypes.func,
189189

190+
/**
191+
* If specified, `rowKeyGetter(index)` is called for each row and the
192+
* returned value overrides `key` for the particular row.
193+
*/
194+
rowKeyGetter: PropTypes.func,
195+
190196
/**
191197
* Pixel height of the column group header.
192198
*/
@@ -666,6 +672,7 @@ var FixedDataTable = React.createClass({
666672
rowsCount={state.rowsCount}
667673
rowGetter={state.rowGetter}
668674
rowHeightGetter={state.rowHeightGetter}
675+
rowKeyGetter={state.rowKeyGetter}
669676
scrollLeft={state.scrollX}
670677
scrollableColumns={state.bodyScrollableColumns}
671678
showLastRowBorder={true}

src/FixedDataTableBufferedRows.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var FixedDataTableBufferedRows = React.createClass({
3838
rowClassNameGetter: PropTypes.func,
3939
rowsCount: PropTypes.number.isRequired,
4040
rowHeightGetter: PropTypes.func,
41+
rowKeyGetter: PropTypes.func,
4142
rowPositionGetter: PropTypes.func.isRequired,
4243
scrollLeft: PropTypes.number.isRequired,
4344
scrollableColumns: PropTypes.array.isRequired,
@@ -136,13 +137,14 @@ var FixedDataTableBufferedRows = React.createClass({
136137
var rowIndex = rowsToRender[i];
137138
var currentRowHeight = this._getRowHeight(rowIndex);
138139
var rowOffsetTop = baseOffsetTop + rowPositions[rowIndex];
140+
var rowKey = props.rowKeyGetter ? props.rowKeyGetter(rowIndex) : i;
139141

140142
var hasBottomBorder =
141143
rowIndex === props.rowsCount - 1 && props.showLastRowBorder;
142144

143145
this._staticRowArray[i] =
144146
<FixedDataTableRow
145-
key={i}
147+
key={rowKey}
146148
isScrolling={props.isScrolling}
147149
index={rowIndex}
148150
width={props.width}

0 commit comments

Comments
 (0)