Luca Davanzo
Luca Davanzo

Reputation: 21520

v6: React-table multiple selection issue

I'm trying to apply a background color on selected rows:

getTrProps={(state, rowInfo, column, instance) => ...}

on rowInfo I can't find any information like "selected" or similar (also using selectTableHOC)

Upvotes: 0

Views: 406

Answers (1)

Savaj Patel
Savaj Patel

Reputation: 535

selected row column

    getTrProps={(state, rowInfo, column) => {
        return {
          onClick: (e) => {
            var a = this.state.selected.indexOf(rowInfo.index);
            if (a == -1) {
              // this.setState({selected: array.concat(this.state.selected, [rowInfo.index])});
              this.setState({selected: [...this.state.selected, rowInfo.index]});
              // Pass props to the React component
            }
            var array = this.state.selected;
            if(a != -1){
              array.splice(a, 1);
              this.setState({selected: array});

            }
          },
          // #393740 - Lighter, selected row
          // #302f36 - Darker, not selected row
          style: {background: this.state.selected.indexOf(rowInfo.index) != -1 ? '#393740': '#302f36'},
        }
        }}

Upvotes: 1

Related Questions