react-table component onClick event for a column

醉酒当歌 提交于 2019-12-18 16:53:13

问题


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:


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} />



回答2:


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.



来源:https://stackoverflow.com/questions/43112105/react-table-component-onclick-event-for-a-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!