Skip to content

Commit

Permalink
changed keys for rows to fix facebook/react#2410
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdmc committed Jan 13, 2016
1 parent bbc9229 commit cb54f35
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
16 changes: 11 additions & 5 deletions build/griddle.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,10 @@ return /******/ (function(modules) { // webpackBootstrap
return myReturn;
},
shouldShowNoDataSection: function shouldShowNoDataSection(results) {
return this.props.useExternal === false && (typeof results === 'undefined' || results.length === 0) || this.props.useExternal === true && this.props.externalIsLoading === false && results.length === 0;
// known issue https://github.com/GriddleGriddle/Griddle/issues/274
// return (this.props.useExternal === false && (typeof results === 'undefined' || results.length === 0 )) ||
// (this.props.useExternal === true && this.props.externalIsLoading === false && results.length === 0)
return false;
},
render: function render() {
var that = this,
Expand Down Expand Up @@ -990,7 +993,7 @@ return /******/ (function(modules) { // webpackBootstrap

var nodes = nodeData.map(function (row, index) {
var hasChildren = typeof row["children"] !== "undefined" && row["children"].length > 0;
var uniqueId = that.props.rowSettings.getRowKey(row);
var uniqueId = that.props.rowSettings.getRowKey(row, index);

//at least one item in the group has children.
if (hasChildren) {
Expand Down Expand Up @@ -1424,7 +1427,7 @@ return /******/ (function(modules) { // webpackBootstrap
paddingHeight: that.props.paddingHeight, rowHeight: that.props.rowHeight })));
}

return React.createElement(that.props.rowSettings.rowComponent, { useGriddleStyles: that.props.useGriddleStyles, isSubGriddle: that.props.isSubGriddle, data: row, columnSettings: that.props.columnSettings, isChildRow: true, columnMetadata: that.props.columnSettings.columnMetadata, key: that.props.rowSettings.getRowKey(row) });
return React.createElement(that.props.rowSettings.rowComponent, { useGriddleStyles: that.props.useGriddleStyles, isSubGriddle: that.props.isSubGriddle, data: row, columnSettings: that.props.columnSettings, isChildRow: true, columnMetadata: that.props.columnSettings.columnMetadata, key: that.props.rowSettings.getRowKey(row, index) });
});
}

Expand Down Expand Up @@ -1461,13 +1464,16 @@ return /******/ (function(modules) { // webpackBootstrap

_createClass(RowProperties, [{
key: 'getRowKey',
value: function getRowKey(row) {
value: function getRowKey(row, key) {
var uniqueId;

if (this.hasRowMetadataKey()) {
uniqueId = row[this.rowMetadata.key];
} else {
uniqueId = _.uniqueId("grid_row");
// commented because of that issue related to rerendering table
// https://github.com/facebook/react/issues/2410
// uniqueId = _.uniqueId("grid_row");
uniqueId = "grid_row_" + key;
}

//todo: add error handling
Expand Down
6 changes: 3 additions & 3 deletions scripts/gridRowContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ var GridRowContainer = React.createClass({

var columns = this.props.columnSettings.getColumns();

arr.push(<this.props.rowSettings.rowComponent
arr.push(<this.props.rowSettings.rowComponent
useGriddleStyles={this.props.useGriddleStyles}
isSubGriddle={this.props.isSubGriddle}
isSubGriddle={this.props.isSubGriddle}
data={this.props.rowSettings.isCustom ? _.pick(this.props.data, columns) : this.props.data}
rowData={this.props.rowSettings.isCustom ? this.props.data : null }
columnSettings={this.props.columnSettings}
Expand Down Expand Up @@ -93,7 +93,7 @@ var GridRowContainer = React.createClass({
</tr>);
}

return <that.props.rowSettings.rowComponent useGriddleStyles={that.props.useGriddleStyles} isSubGriddle={that.props.isSubGriddle} data={row} columnSettings={that.props.columnSettings} isChildRow={true} columnMetadata={that.props.columnSettings.columnMetadata} key={that.props.rowSettings.getRowKey(row)} />
return <that.props.rowSettings.rowComponent useGriddleStyles={that.props.useGriddleStyles} isSubGriddle={that.props.isSubGriddle} data={row} columnSettings={that.props.columnSettings} isChildRow={true} columnMetadata={that.props.columnSettings.columnMetadata} key={that.props.rowSettings.getRowKey(row, index)} />
});
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/gridTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var GridTable = React.createClass({

var nodes = nodeData.map(function(row, index){
var hasChildren = (typeof row["children"] !== "undefined") && row["children"].length > 0;
var uniqueId = that.props.rowSettings.getRowKey(row);
var uniqueId = that.props.rowSettings.getRowKey(row, index);

//at least one item in the group has children.
if (hasChildren) { anyHasChildren = hasChildren; }
Expand Down
7 changes: 5 additions & 2 deletions scripts/rowProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ class RowProperties{
this.isCustom = isCustom;
}

getRowKey(row) {
getRowKey(row, key) {
var uniqueId;

if(this.hasRowMetadataKey()){
uniqueId = row[this.rowMetadata.key];
}
else{
uniqueId = _.uniqueId("grid_row");
// commented because of that issue related to rerendering table
// https://github.com/facebook/react/issues/2410
// uniqueId = _.uniqueId("grid_row");
uniqueId = "grid_row_" + key;
}

//todo: add error handling
Expand Down

0 comments on commit cb54f35

Please sign in to comment.