'react-table add edit/delete column

I use Rails and React-Table to display tables. It works fine so far. But How can one add an edit/delete column to the React-Table?

Is it even possible?

return (
    <ReactTable
      data={this.props.working_hours}
      columns={columns}
      defaultPageSize={50}
      className="-striped -highlight"
    />
    )


Solution 1:[1]

All you need to do is turn columns into a component state. You can see a working example https://codesandbox.io/s/0pp97jnrvv

[Updated 3/5/2018] Misunderstood the question, here's the updated answer:

const columns = [
    ...
    {
       Header: '',
       Cell: row => (
           <div>
               <button onClick={() => handleEdit(row.original)}>Edit</button>
               <button onClick={() => handleDelete(row.original)}>Delete</button>
           </div>
       )
    }
]

where handleEdit and handleDelete will be the callbacks how you want to handle the actions when the buttons are clicked.

Solution 2:[2]

You can actually add buttons using the accessor prop of the columns in react-table. here is code example:

     {
        Header: 'Action',
        accessor: (originalRow, rowIndex) => (
           <div>
               <button onClick={() => handleEdit(originalRow)}>Edit</button>
               <button onClick={() => handleDelete(originalRow)}>Delete</button>
           </div>
        ),
        id: 'action',
      },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Jibran Haseeb