forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Table] Fix controlled behavior (mui#6638)
- Loading branch information
1 parent
3421207
commit ce4035c
Showing
9 changed files
with
339 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
docs/src/app/components/pages/components/Table/ExampleControlled.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, {Component} from 'react'; | ||
import { | ||
Table, | ||
TableBody, | ||
TableHeader, | ||
TableHeaderColumn, | ||
TableRow, | ||
TableRowColumn, | ||
} from 'material-ui/Table'; | ||
|
||
export default class TableExampleControlled extends Component { | ||
state = { | ||
selected: [1], | ||
}; | ||
|
||
isSelected = (index) => { | ||
return this.state.selected.indexOf(index) !== -1; | ||
}; | ||
|
||
handleRowSelection = (selectedRows) => { | ||
this.setState({ | ||
selected: selectedRows, | ||
}); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Table onRowSelection={this.handleRowSelection}> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHeaderColumn>ID</TableHeaderColumn> | ||
<TableHeaderColumn>Name</TableHeaderColumn> | ||
<TableHeaderColumn>Status</TableHeaderColumn> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
<TableRow selected={this.isSelected(0)}> | ||
<TableRowColumn>1</TableRowColumn> | ||
<TableRowColumn>John Smith</TableRowColumn> | ||
<TableRowColumn>Employed</TableRowColumn> | ||
</TableRow> | ||
<TableRow selected={this.isSelected(1)}> | ||
<TableRowColumn>2</TableRowColumn> | ||
<TableRowColumn>Randal White</TableRowColumn> | ||
<TableRowColumn>Unemployed</TableRowColumn> | ||
</TableRow> | ||
<TableRow selected={this.isSelected(2)}> | ||
<TableRowColumn>3</TableRowColumn> | ||
<TableRowColumn>Stephanie Sanders</TableRowColumn> | ||
<TableRowColumn>Employed</TableRowColumn> | ||
</TableRow> | ||
<TableRow> | ||
<TableRowColumn selected={this.isSelected(3)}>4</TableRowColumn> | ||
<TableRowColumn>Steve Brown</TableRowColumn> | ||
<TableRowColumn>Employed</TableRowColumn> | ||
</TableRow> | ||
</TableBody> | ||
</Table> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.