React-table: How to access to another column's value from a column

Created on 24 Oct 2017  路  2Comments  路  Source: tannerlinsley/react-table

I have a column named "Status" and another column named "Action"
Under default situation, all action will be "edit"
However when status is "canceled" action should become "delete".
How can i make this?

Most helpful comment

you can access the entire row's data via the Cell property in the columns. You'd basically just conditionally render what you want based on the value of the other column, or track it in local state accordingly.

I do this with inline edit fields, when a user click the edit button I toggle this.state.isEditing to true and render the inputs and save buttons, otherwise they're rendered as span's

es6 const columns= [ { Header: 'Some Other Column', accessor: 'SomeOtherColumn' }, { Header: 'Column 2', Cell: ({ row, original }) => { return (<span> {original.SomeOtherColumn} </span>) } } ]

All 2 comments

you can access the entire row's data via the Cell property in the columns. You'd basically just conditionally render what you want based on the value of the other column, or track it in local state accordingly.

I do this with inline edit fields, when a user click the edit button I toggle this.state.isEditing to true and render the inputs and save buttons, otherwise they're rendered as span's

es6 const columns= [ { Header: 'Some Other Column', accessor: 'SomeOtherColumn' }, { Header: 'Column 2', Cell: ({ row, original }) => { return (<span> {original.SomeOtherColumn} </span>) } } ]

Mike is correct. Use a custom Cell - check the doco for more details.

Also, please join the #react-table Slack channel for questions of this nature rather than using the github issue facility. This is mainly for the development pipeline and reporting bugs. You can find a badge at the top of the documentation. Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schaeffer11 picture schaeffer11  路  24Comments

IPessers picture IPessers  路  20Comments

Paul6552 picture Paul6552  路  35Comments

vaidsu picture vaidsu  路  29Comments

larrybotha picture larrybotha  路  20Comments