0

I successfully use export default React.createClass to handle a Boostrap Modal and a Griddle table.

Now I want to open the Modal when a user clicks on a specific column of Griddle. This is done by using a custom component that handles the click code/event. But since the custom component is defined as a new different class var editData = React.createClass I cannot access the state of the main class to open the modal.

How should I proceed? Here down the code, I DO NOT KNOW is the part I'm missing.

Thanks Karl

var editData = React.createClass({
    render: function() {
        return (
            <div onClick={I DO NOT KNOW}> 
                Edit row data for id {this.props.rowData.id}
            </div>
        )
    }
})

var columns = ["id", "name", "edit"]

var columnMeta = [{
    columnName: "edit",
    customComponent: editData
}]

export default React.createClass({

    close() {this.setState({ showModal: false })},

    open() {this.setState({ showModal: true })},    

    render() {
        return (<div>
        <Modal show={this.state.showModal} onHide={this.close}>
        <Modal.Header closeButton>
        <Modal.Title>Modal heading</Modal.Title>
        </Modal.Header>
        <Modal.Body>
        Text in a modal
        </Modal.Body>
        <Modal.Footer>

        <Griddle columns={columns} columnMetadata={columnMeta} />
        </div>)
    }

})
Karl
  • 55
  • 1
  • 1
  • 7

1 Answers1

0

Solved by passing a function in the props. Here down what I've done.

var editData = React.createClass({

    handleChange(){
        this.props.metadata.onChange("your value here")
    },

    render: function() {
        return (
            <div onClick={this.handleChange}> 
                Edit row data for id {this.props.rowData.id}
            </div>
        )
    }
})

var columns = ["id", "name", "edit"]

export default React.createClass({

    handleChange(e){
        console.log(e)
    },

    close() {this.setState({ showModal: false })},

    open() {this.setState({ showModal: true })},    

    render() {

        var columnMeta = [{
            columnName: "edit",
            customComponent: editData,
            onChange: this.handleChange
        }]

        return (<div>
        <Griddle columns={columns} columnMetadata={columnMeta} />
        </div>)
    }

})
Karl
  • 55
  • 1
  • 1
  • 7