Select row on click react-table

后端 未结 7 918
广开言路
广开言路 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 06:58

    I am not familiar with, react-table, so I do not know it has direct support for selecting and deselecting (it would be nice if it had).

    If it does not, with the piece of code you already have you can install the onCLick handler. Now instead of trying to attach style directly to row, you can modify state, by for instance adding selected: true to row data. That would trigger rerender. Now you only have to override how are rows with selected === true rendered. Something along lines of:

    // Any Tr element will be green if its (row.age > 20) 
     {
        return {
          style: {
            background: rowInfo.row.selected ? 'green' : 'red'
          }
        }
      }}
    />
    

提交回复
热议问题