Select row on click react-table

后端 未结 7 900
广开言路
广开言路 2020-12-08 06:29

I am trying to find the best table to use with my react apps, and for now, the react-table offers everything I need (pagination, server-side control, filtering, sorting, foo

相关标签:
7条回答
  • 2020-12-08 07:12

    The answer you selected is correct, however if you are using a sorting table it will crash since rowInfo will became undefined as you search, would recommend using this function instead

                    getTrGroupProps={(state, rowInfo, column, instance) => {
                        if (rowInfo !== undefined) {
                            return {
                                onClick: (e, handleOriginal) => {
                                  console.log('It was in this row:', rowInfo)
                                  this.setState({
                                      firstNameState: rowInfo.row.firstName,
                                      lastNameState: rowInfo.row.lastName,
                                      selectedIndex: rowInfo.original.id
                                  })
                                },
                                style: {
                                    cursor: 'pointer',
                                    background: rowInfo.original.id === this.state.selectedIndex ? '#00afec' : 'white',
                                    color: rowInfo.original.id === this.state.selectedIndex ? 'white' : 'black'
                                }
                            }
                        }}
                    }
    
    0 讨论(0)
提交回复
热议问题