-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Setting state with the selectedRows has unexpected results #2747
Comments
Now with the same code I had in earlier (that worked earlier), it doesn't work now.
EDIT And now works after undoing and redoing in text editor. Though the first point still doesn't work. |
Nor does this table function correctly with this:
|
Not being able to update the state with the selected rows makes its functionality almost useless. |
Not even being able to select a row (not even animations or the checkbox being clicked) if your |
It seems that setting the state in that function is somehow resetting the state. If I put a timeout, the row is checked then once it fires, it unchecks itself and the |
This is me not knowing enough about React. Need to make sure render isn't called after setting its state. |
@stevenmwade I'm glad you found a solution. Sometime just exposing the issue help 😁. |
@oliviertassinari Although |
I'm having the same issue - can you elaborate on your final solution? Trying to setState with the indices of selected rows for later processing. Thanks! |
Found a solution: constructor() {
super();
this.state = {
selectedRows: []
};
this._onRowSelection = this._onRowSelection.bind(this);
}
render() {
return (
<Table multiSelectable onRowSelection={this._onRowSelection}>
<TableHeader>
<TableRow>
<TableHeaderColumn>c1</TableHeaderColumn>
<TableHeaderColumn>c2</TableHeaderColumn>
<TableHeaderColumn>c3</TableHeaderColumn>
</TableRow>
</TableHeader>
<TableBody showRowHover ref={(tableBody) => { this.tableBody = tableBody; }}>
{this._renderTableRow()}
</TableBody>
</Table>
);
}
_onRowSelection(rows: Array<number>) {
this.setState({selectedRows: rows}, () => this.tableBody.setState({ selectedRows: rows }));
} |
When I use this pattern, then the table no longer behaves correctly. Checkboxes don't check and
selectedRow
array only has one index. I want it passed up because it needs to be passed to another component. But just the presence of thesetState
causes this.Also,
onRowSelection
gets fired when the table is rerendered and there are rows are selected (but not when there are none selected).The text was updated successfully, but these errors were encountered: