Supposing I have this parent component.
Parent.jsx
render() { const headers = ["id","desc1", "desc2", "actions"]; return( <div> <input type = "text" placeholder = "Product Brand" value={ this.state.desc }/> <input type = "text" placeholder = "Product Brand" value={ this.state.desc2 }/> <button type = "button" onClick = { this.handleSubmit.bind(this) }>Add</button> <CustomTable mystate = { this.state } header = { headers } data = { this.props.store.productbrandlist }/> </div> ) } and this CustomTable.jsx
renderHeaders(){ return( this.props.header.map(function(header, index){ return <th key={index}>{header}</th> }) ) } renderRows(){ // console.log("here1"); // return( // <ListItem datarows = { this.props.data }/> // ) return this.props.data.map((list, id) => <ListItem mystate = {this.props.mystate} key_id={id} key={id} col = {list}/> ) } render(){ return( <table className="table"> <thead> <tr>{ this.renderHeaders() }</tr> </thead> <tbody> { this.renderRows() } </tbody> </table> ) } and this component which render the rows of the table
render(){ return( <tr key = { this.props.key_id }> { this.renderColumns() } { this.renderActions() } </tr> ) } renderColumns(){ var columns = [] for (var key in this.props.col) { if (this.state.isEditing){ columns.push(<td key = {key.id}><input ref = "txt" type = "text" value = { this.state.itemValue } onChange = { this.onTextChange.bind(this) } /></td>) } else { columns.push(<td key = {key.id}>{ this.props.col[key] }</td>) // this.setState({ // itemValue: key, // isEditing: false // }) } } return columns } renderActions(){ if (this.state.isEditing){ return ( <td> <button type="button" onClick = { this.handleSaveClick.bind(this) }>Save</button> <button type="button" onClick = { this.handlCancelClick.bind(this) }>Cancel</button> </td> ) } return( <td> <button type="button" onClick = { this.handleEditClick.bind(this) }>Edit</button> <button type="button" onClick = { this.handleDeleteClick.bind(this) }>Delete</button> </td> ) } My question is how do I configure it in such a way that when I click on the button edit which is created in the ListItem Component. The data will be displayed in the inputbox which is created in the parent.jsx