Griddle supports subgrids. I have a custom component (used for row selection) in one of the fields that changes the state. This state change causes a re-render, which collapses the subgrid. However, I'd like it to stay open.
This same problem is documented in this Github issue, including this example (thanks @denzelby of Github) in which filtering collapses the subgrids.
Note in the code from the fiddle how the state is updated onCountClick (clicking the "inc" button), causing the re-render:
var GridAndCounter = React.createClass({
render: function() {
var columnNames = ['id', 'age', 'name', 'company', 'state', 'country', 'favoriteNumber'];
var rowMetadata = {key: "id"};
return <div><Counter count={this.state.count} onClick={this.onCountClick} /><Griddle results={fakeData} rowMetadata={rowMetadata} columnNames={columnNames} resultsPerPage={100} showFilter={true} /></div>
},
onCountClick: function() {
React.addons.Perf.start();
this.setState({count: this.state.count + 1 });
setTimeout(function() {
React.addons.Perf.stop();
React.addons.Perf.printDOM();
}, 500);
},
getInitialState: function() {
return { count: 0 };
}
})
This state update causes a re-render which sets everything to collapsed. How can I keep everything expanded on re-render? I could perhaps track which ones are expanded myself, but then I would need a programmatic way to expand the rows, which I haven't discovered with Griddle.
Looking at the github source of Griddle,
gridRowContainer.jsxuses state to determine whether the row is collapsed or not, and forcesshowChildrentofalsein itsgetInitialState()andcomponentWillReceiveProps().Two possible causes:
componentWillReceiveProps()is called whenever props change - and there are lots of props unrelated to 'showing children', so any prop change could introduce the unwanted side-effect you describe!Suggestion: Try removing the setting of
showChildrenincomponentWillReceiveProps()ofgridRowContainer.jsxLess likely: If Griddle is creating entirely new components with each change of the filter (I haven't checked!), then
getInitialState()would cause all rows to collapse. It would then need a considerable rewrite of the parent components to preserve showChildren.I thought about storing
showChildrenin the data itself, and passing your container's handler functionsetShowChildrenthrough to thegridRowContainer.jsxcomponent (as you might do with redux), but that would get messy.