仅在 p:dataTable 中禁用几行的行选择 [英] Disable row selection for a few rows only in a p:dataTable
问题描述
我想知道是否有一种方法可以根据 bean 属性为 Primefaces 中的给定行集禁用基于单选的行选择.
I would like to know if there is a way of disabling the radio-based row selection for a given set of rows in Primefaces, based on a bean property.
示例:
<p:dataTable var="foo" value="#{bean.foos}" selection="#{bean.selectedFoo}">`
<p:column selectionMode="single" />
<p:column>
<h:outputText value="#{foo.bar}" />
</p:column>
<p:dataTable>
在这种情况下,假设我想禁用 foo.bar == 1,5,10
的行,通过禁用行我的意思是禁用与该行关联的单选按钮.
In this case, imagine I would like to disable the rows where foo.bar == 1,5,10
, by disabling the rows I mean disable the radio button associated with the row.
我想不出实现这一目标的方法……有什么想法吗?即使是 css + javascript hack 解决方案也是可以接受的.
I couldn't figure out a way of accomplish that... any ideas? Even a css + javascript hack solution would be acceptable.
推荐答案
从 4.0 版本开始,Primefaces 数据表带有 disabledSelection
属性.
Since 4.0 version, Primefaces datatable comes with a disabledSelection
property.
<p:dataTable var="foo" value="#{bean.foos}" selection="#{bean.selectedFoo}" disabledSelection="#{foo.bar == 1}">
<p:column selectionMode="single" />
<p:column>
<h:outputText value="#{foo.bar}" />
</p:column>
<p:dataTable>
然后,当 foo.bar == 1
为真时,复选框将被禁用.
Then, when foo.bar == 1
is true, checkbox will be disabled.
这篇关于仅在 p:dataTable 中禁用几行的行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!