Reputation: 395
I using the example provided by React, and I want to have a button on every row and when it is clicked a row to be deleted.
https://codesandbox.io/s/5vy2q8owj4?from-embed
I am new to reactjs, it is possible to do it?
What I thought to do is to add another row with a button and inside the component to have a function like this, I don't know how to call this function from the outside:
{ key: "", name: "", formatter: () => <button onClick={() =>
this.deleteRows(title)}>Delete</button>}
deleteRows = (id) => {
let rows = this.state.rows.slice()
rows = rows.filter(row => row.id !== id)
this.setState({ rows })
}
Thanks
Upvotes: 0
Views: 5944
Reputation: 731
It's possible. You may use getCellActions to achieve this. Here's a working example: https://codesandbox.io/s/5091lpolzk
Upvotes: 2