Button click triggers onRowSelect
I have added a column with buttons in my app and the table is set to allow row select as well. However, when a button is clicked, select row is also triggered. Is there a way to avoid this and only allow for the button click when clicked on top of the button ??
@AchinthaReemal, sorry for lately reply. so did you hope the user can select row only by clicking the selection columns? I means clickToSelect: true is that necessary to you?
BTW, if you really need the clickToSelect, I thinks you can implements onSelect and return false if the clicking is on specified column, which means will not select the row
function onRowSelect(row, isSelected, e) {
// if column index is 2, will not trigger selection
if (e.target.cellIndex === 2) return false;
}
const selectRowProp = {
mode: 'checkbox',
clickToSelect: true,
onSelect: onRowSelect
};
export default class SelectHookTable extends React.Component {
render() {
return (
<BootstrapTable data={ products } selectRow={ selectRowProp }>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
}
Hey @ AchinthaReemal i have the same issue than you. Did you solved it?
@pablocordoba11, above example doesn't help you?
@AllenFang It does not work. Well, your example does work, but if you have something like this:
const buttonFormatter = (cell, row) => {
return <Button onClick={() => someFunction(row)}>Click me</Button>;
};
return (
<BootstrapTable data={props.data} striped>
<TableHeaderColumn dataField={item.dataField} dataFormat={buttonFormatter}>
{item.dataName}
</TableHeaderColumn>
</BootstrapTable>
);
It will not work. Button click returns undefined in e.target.cellIndex. However, one can make it work by having some boolean flag stored in state and switching it by clicking.