Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-table component onClick event for a column

I am using the 'react-table' component https://react-table.js.org

I want to add on click event for one column (later I will open a modal showing info based on this event).

like image 724
YO Developer Avatar asked Mar 30 '17 08:03

YO Developer


2 Answers

You add getTrProps to ReactTable like the example:

const onRowClick = (state, rowInfo, column, instance) => {
    return {
        onClick: e => {
            console.log('A Td Element was clicked!')
            console.log('it produced this event:', e)
            console.log('It was in this column:', column)
            console.log('It was in this row:', rowInfo)
            console.log('It was in this table instance:', instance)
        }
    }
}


<ReactTable data={[]} columns={[]} getTrProps={onRowClick} />
like image 154
z0r0 Avatar answered Sep 22 '22 07:09

z0r0


At the time of this writing, React-Table 6.8.0:

The value of 'column' in 'getTrProps' property is always undefined.

You'll have to use 'getTdProps' property instead.

like image 21
EwyynTomato Avatar answered Sep 19 '22 07:09

EwyynTomato