Enabling checkbox locking in datatable
Is there a way in Primefaces to enable or disable a checkbox in a datatable? Right now my datatable looks like this:
<p:dataTable id="dTable" var="tt" value="#{aBean.aList}" selection="#{aBean.selectedValue}" rowStyleClass="#{tt.state.intValue() le 1 ? 'active' : 'passive'}">
<p:column selectionMode="multiple" />
...
</dataTable>
but this code just puts the checkbox column along with the checkbox in the header. I want the checkboxes to be displayed according to the value in the bean base.
source to share
FWIW many years later ...
In PF 5.x you know how to do this in a column, you need to set criteria disabledSelection
in a tag <p:datatable ...>
.
Something like:
<p:datatable disabledSelection="#{myvar ne null}" ... >
It took me a little while to figure out why questions are frequently asked (everywhere) and answered regardless of version. This is where I finally found the answer.
source to share
I found a solution inside PF here: http://forum.primefaces.org/viewtopic.php?f=3&t=14029 Using rowstyleclass and css solved the problem:
XHTML:
<p:dataTable id="dTable" var="tt" value="#{aBean.aList}"
selection="#{aBean.selectedValue}" rowStyleClass="#{tt.state.intValue() le 1 ? 'active' : 'passive'}">
<p:column selectionMode="multiple"/>
...
</dataTable>
CSS
.active{
background-image: none !important;
}
.passive{
background-color:gainsboro !important;
background-image: none !important;
}
.passive td.ui-selection-column input {
display:none;
}
This enables / disables the command button using CSS.
source to share
try it disabledSelection
<p:column
You can always do it without it, just do it manually ... by posting
And you can use
rowIndexVar: the name of the iterator to access each row index.
to reference the line number
And this is how the select column should look like (more or less)
used the class checkall
to delegate it later with jQuery and doselect all magic
<p:column id="selection_column">
<f:facet name="header">
<h:selectBooleanCheckbox value="" class="checkall"/>
</f:facet>
<h:selectBooleanCheckbox rendered="#{myRow.selectable}" value="#{myRow.selected}"/>
</p:column>
jQuery(window).load(function() {
jQuery(document).delegate(".checkall", "click", function(event) {
jQuery(this).closest("table").find(':checkbox').attr('checked', this.checked);
});
});
source to share