9

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).

1
  • if you look at their docs....... click custom props.... it shows how you can have a click event on a table row. Commented Mar 30, 2017 at 8:20

2 Answers 2

20

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} />
Sign up to request clarification or add additional context in comments.

2 Comments

For some reason, I am only getting a value back for "rowInfo" and not state, column, or instance. I cannot find out why this might be the case. Please help?
I am having the same issue
5

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.

2 Comments

This package is so bad. Hard to find documentation for some important features:(
The package in itself is not that bad but the documentation certainly is!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.