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

How to stop row expanding when clicking a component inside a cell?

Open ashcorah opened this issue 7 years ago • 9 comments

image

I want the row to expand when I click the row however I don't want it to expand when clicking an element. For example clicking this component for a menu, expands the row - but I want it to only expand when I click the row itself not the components inside the cells.

Anyway to do this?

ashcorah avatar Feb 14 '19 12:02 ashcorah

@AshCorah for your last column, did you use formatter to custom the content, right?

AllenFang avatar Feb 17 '19 07:02 AllenFang

I think so far I can not control it but I will figure out if there's some way can achieve your requirement, thanks

AllenFang avatar Feb 17 '19 07:02 AllenFang

btw, there's a expandRow.expandByColumnOnly option, you can disable it when you only want to user to expand on clicking the expand columns. But I think this is not fit your request at all lol

AllenFang avatar Feb 17 '19 07:02 AllenFang

The other solution is you can call e.stoppropagation() when clicking on your component.

const Pricer = ({ cell }) => {
  const onClick = e => e.stopPropagation();
  return (
    <span onClick={ onClick }>
      <strong style={ { color: 'red' } }>$ { cell } NTD(Sales!!)</strong>
    </span>
  );
};

function priceFormatter(cell) {
  return (
    <Pricer cell={ cell } />
  );
}

const columns = [{
  dataField: 'id',
  text: 'Product ID'
}, {
  dataField: 'name',
  text: 'Product Name'
}, {
  dataField: 'price',
  text: 'Product Price',
  formatter: priceFormatter
}];

AllenFang avatar Feb 17 '19 07:02 AllenFang

Let me know if above solutions are not work for you, thanks

AllenFang avatar Feb 17 '19 09:02 AllenFang

This worked for me, thanks so much :)

ashcorah avatar Feb 18 '19 17:02 ashcorah

👍

AllenFang avatar Feb 19 '19 05:02 AllenFang

This really helps, Thanks !!

lavania-aditya avatar May 25 '20 06:05 lavania-aditya

In June 2022 I have the same issue, it works now. You saved my day, thank you !

LegitOverAll avatar Jun 04 '22 09:06 LegitOverAll