0

I'm trying to migrate my application which currently uses react-bootstrap-table to react-bootstrap-table-next but I'm having a problem.

What I am trying to do:

is to get the object of the selected line.

My code

const selectRow = {
        mode: 'radio',
        hideSelectColumn: true,
        clickToSelect: true,
        bgColor: 'red',
        onSelect: (row) => {
           console.log(row)
          }
      };

<div className="col-lg-12">
                             <BootstrapTable keyField='id' data={ products } columns={ columns } selectRow={ selectRow }   />
                        </div>

result obtained

When I click on the line, it assigns the color red and prints the object to the selected line

but when I try to put the object in the state:

const selectRow = {
        mode: 'radio',
        hideSelectColumn: true,
        clickToSelect: true,
        bgColor: 'red',
        onSelect: (row) => {
           console.log(row)
           this.setState({banco: row});
          }
      };

The selected line object is assigned to {banco} property as expected, but the line does not turn red.

1 Answers1

0

I think you need to check this. As the above link mention, right now there's only one workaround is when you need to call setState in selectRow.onSelect, please also manage the selection by yourself via selectRow.selected I'm the creator of react-bootstrap-table and we will improve this issue in the future. Please follow above link to have a workaround, thanks

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
AllenFang
  • 161
  • 2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/20270411) – ilim Jul 11 '18 at 15:00
  • As the above link mention, right now there's only one workaround is when you need to call `setState` in `selectRow.onSelect`, please also manage the selection by yourself via `selectRow.selected` – AllenFang Jul 11 '18 at 15:17