Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-table add edit/delete column

Tags:

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"     />     ) 
like image 330
Trinity76 Avatar asked Feb 23 '18 10:02

Trinity76


People also ask

How do you make a row editable in react?

React Data Grid: Full Row Editing. Full row editing is for when you want all cells in the row to become editable at the same time. This gives the impression to the user that the record the row represents is being edited. To enable full row editing, set the grid option editType = 'fullRow' .

How do I delete a row from a table in react JS?

Delete row from a table, deleteRow(id), remove() or use useState () in Reactjs.


1 Answers

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.

like image 95
Rico Chen Avatar answered Sep 29 '22 04:09

Rico Chen