I want to use the table from the material library for the reaction: http://www.material-ui.com/#/components/table
I show it, it works very well, I try to get the object associated with the string I selected, but I did not find a way to do this, I saw the children or onRowSelection , but I can not get my object here, this is the code. How can I get the whole object of my selected line?
import React, { PropTypes, Component } from 'react' import Table from 'material-ui/lib/table/table'; import TableHeaderColumn from 'material-ui/lib/table/table-header-column'; import TableRow from 'material-ui/lib/table/table-row'; import TableHeader from 'material-ui/lib/table/table-header'; import TableRowColumn from 'material-ui/lib/table/table-row-column'; import TableBody from 'material-ui/lib/table/table-body'; export default class MagicTableReact extends Component { constructor(props) { super(props); this.state = { data : [{id:0,name:"joe"},{id:1,name:"john"},{id:2,name:"Brad"},{id:3,name:"Jack"},{id:4,name:"Andrew"}], fixedHeader: true, fixedFooter: true, stripedRows: false, showRowHover: true, selectable: true, multiSelectable: false, enableSelectAll: false, deselectOnClickaway: true, height: '300px', }; }; _onRowSelection(e){ console.log(e) } render() { return ( <div> <div className="col-sm-6"> <h1>MagicTableReact</h1> <Table height={this.state.height} fixedHeader={this.state.fixedHeader} fixedFooter={this.state.fixedFooter} selectable={this.state.selectable} multiSelectable={this.state.multiSelectable} > <TableHeader> <TableRow> <TableHeaderColumn>ID</TableHeaderColumn> <TableHeaderColumn>Name</TableHeaderColumn> </TableRow> </TableHeader> <TableBody > {this.state.data.map((user, i) => <TableRow key={i} onRowSelection={this._onRowSelection.bind(this)}> <TableRowColumn>{user.id}</TableRowColumn> <TableRowColumn>{user.name}</TableRowColumn> </TableRow> )} </TableBody> </Table> </div> </div> ) } } MagicTableReact.propTypes = { };
source share