react-bootstrap-table icon indicating copy to clipboard operation
react-bootstrap-table copied to clipboard

onSelect and mode: 'radio',

Open stephanebarbey opened this issue 10 years ago • 2 comments

When using the table with mode: 'radio', I only get an onSelect event with isSelected true for the new selection, but there is not event for the "unselected" item. (I would have expected to receive two events, an isSelected=false for the previously selected item, and isSelected=true for the newly selected item.)

This behaviour makes it hard to create generic (for both modes) components on top of the react-bootstrap-table that handle the selection state.

Actually, what I would like to have is an afterSelect event, that is triggered after a selection change is done (not before, like onSelect, which is also useful). Otherwise, one has to manage the selected rows state oneself, which can be difficult when you have a chain of onSelect callbacks.

Or do I miss something?

Thanks, -Stephane

stephanebarbey avatar Nov 20 '16 17:11 stephanebarbey

@stephanebarbey : What would you do with the unselected one? You would be more interested on the selected one at any point of time if it is a radio button, right?

I used to do this always:

  • Create a state variable
  • When selected add that row in the state variable

The state variable will always have one row.

If it is a checkbox, I push or pop from the state variable based on the isSelected.

Ideally speaking, the isSelected for the radio is not at all required in my point of view. What do you say @AllenFang ?

email2vimalraj avatar Nov 21 '16 06:11 email2vimalraj

The state variable will always have one row.

If it is a checkbox, I push or pop from the state variable based on the isSelected.

Ideally speaking, the isSelected for the radio is not at all required in my point of view.

@email2vimalraj absolutely right.

you can get the unselect item by current state before you change it when onSelect is done

AllenFang avatar Nov 21 '16 12:11 AllenFang