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.jsx
uses state to determine whether the row is collapsed or not, and forces showChildren
to false
in its getInitialState()
and componentWillReceiveProps()
.
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 showChildren
in componentWillReceiveProps()
of gridRowContainer.jsx
Less 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 showChildren
in the data itself, and passing your container's handler function setShowChildren
through to the gridRowContainer.jsx
component (as you might do with redux), but that would get messy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With