AllenFang / react-bootstrap-table

A Bootstrap table built with React.js
https://allenfang.github.io/react-bootstrap-table/
MIT License
2.24k stars 783 forks source link

How to bind the multiple row selection values #2074

Open Bharathsiva opened 5 years ago

Bharathsiva commented 5 years ago

Hi @AllenFang, I want to bind the selected multiple row selection values in this.setstate but i can't bind the values.kindly help me to solve this issue. here is my code

const selectRowProp = {
  mode: 'checkbox',
  bgColor: 'rgb(219, 61, 68)',
  clickToSelect: true,
  selected:[this.state.pricetype],
  onSelect: onRowSelect.bind(this),
  onSelectAll: onSelectAll

};

    var indexArray=[];

    function onRowSelect(row, isSelected) {
      var tempArray=[];
      var tempCount=0;

  for(var i=0; i < indexArray.length;i++)
    {
            if(indexArray[i] === row.pricecode){
                 if(isSelected && indexArray.length <= 3)
                        {

                            tempArray.push(row.pricecode);

                        }
                 else {
                        tempCount++;
                       }

                }

            else{
                    if(tempArray.length <= 3)
                    {
                      tempArray.push(indexArray[i]);
                    }

                }   

      }

      if(indexArray.length+1 >3){
        alert('You can only select three price code');
        return false;
      }

      if(tempCount === 0 && indexArray.length <= 2)
      {
           tempArray.push(row.pricecode);
         }

         indexArray = tempArray
        //  var y = indexArray.toString()
          this.setState({pricetype: indexArray});
        alert(this.state.pricetype)

      // console.log(y);
    //  alert(`is selected: ${isSelected},`,this.state.pricetype);
    }

below is my JSX

<div className="col-md-4">
                            <BootstrapTable data={ data1 } selectRow={ selectRowProp }>
                              <TableHeaderColumn dataField='pricecode' value={this.state.pricetype}  name = "pricetype" isKey={ true }>Price Type Code</TableHeaderColumn>
                            </BootstrapTable>
                        </div>