Search code examples
javascriptjsfrichfacesonrowclick

Avoid onRowClick event in certain column of rich:dataTable


I have a rich:dataTable which contains 4 columns.

The first one is a selectBooleanCheckBox, which fires an event called "CheckEvent" (just for the example) into the bean.

Meanwhile, the dataTable also supports the onRowClick event, which fires "onRowClick" on the bean.

The problem I'm facing is that when I click on the first column (the check one), the onRowClick also fires. This certainly is a problem in this situation: if a row has the check selected and I just want to deselect it, the onRowClick highlights the row, a behaviour I don't want.

I've tried to define the oOnRowClick event inside the other three rich:columns, but what I achieve this way is nothing; that the event doesn't even trigger, so there's no onRowClick for the datatable.

Trying to make the logic via the bean doesn't work either, since I don't know which column is pushed when I enter the onRowClick() method.

I'm really desperate about this. Any help would be kindly appreciated.


Solution

  • onrowclick adds onclick on the table row, if you don't want it to fire you have to prevent the click event on the checkbox from bubbling up to the row, e.g.:

    <h:selectBooleanCheckbox onclick="event.stopPropagation()" … />