Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide p:dataTable selection checkbox based on row criteria

I have implemented org.primefaces.model.SelectableDataModel.

Now when rendering my <p:dataTable> based on the SelectableDataModel I add a column with checkboxes by using:

<p:column selectionMode="multiple" /> 

For some rows I do not want the checkbox to appear, based on some attribute of the row.

I cannot see a way to do this. Is it possible with out the box Prime Faces functionality ?

like image 960
planetjones Avatar asked Feb 19 '13 14:02

planetjones


2 Answers

You can disable the checkbox:

<p:column selectionMode="multiple" style="width:18px" 
   disabledSelection="#{car.color =='Black'}" 
   styleClass="#{car.color =='Black' ? 'selectionDisabled':''}"/>

The check box is now disabled, however, visible. Hide disabled checkbox with CSS:

td.selectionDisabled .ui-chkbox{
display: none;
}
like image 150
maciek Avatar answered Nov 11 '22 15:11

maciek


I would suggest to use:

<p:dataTable disabledSelection="#{car.color =='Black'}" ... >

For me it works fine with PF 5.1. No need to manipulate column styleClass.

like image 37
user4165984 Avatar answered Nov 11 '22 15:11

user4165984