我正在使用:
服务器:Wildfly 8.2 JSF:2.2 Primefaces:5.2 JDK:8
我有一个有多个选择的数据表。我使用rowSelectMode='add'
所以点击不带修改键的不同行会添加新行而不是取消选中所有选定的行。
<p:dataTable id="table"
value="#{ixController.files}"
var="item" paginatorTemplate="{FirstPageLink} {PreviousPageLink}
{PageLinks}
{NextPageLink} {LastPageLink}"
selection="#{ixController.selecteds}"
rowKey="#{item.id}"
rowSelectMode="add"
selectionMode="multiple">
<p:column headerText="Files">
#{item.fileName}
</p:column>
如上所述,它适用于添加行,但我需要按Ctrl键取消选择行,客户希望再次单击该行并取消选择它。
这有可能吗?
答案 0 :(得分:0)
使用复选框,他们可以通过单击选择和取消选择,按照Prime Faces示例:
<p:dataTable id="checkboxDT" var="car" value="#{dtSelectionView.cars6}" selection="#{dtSelectionView.selectedCars}" rowKey="#{car.id}" style="margin-bottom:0">
<f:facet name="header">
Checkbox
</f:facet>
<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
<f:facet name="footer">
<p:commandButton process="checkboxDT" update=":form:multiCarDetail" icon="ui-icon-search" value="View" oncomplete="PF('multiCarDialog').show()" />
</f:facet>
</p:dataTable>
答案 1 :(得分:0)
我无法找到这方面的原因,但有一种方法:
<p:dataTable value="#{groupBean.groups}" var="grp" rowKey="#{grp.id}"
selectionMode="single" selection="#{groupBean.group}">
<p:ajax event="rowSelect" listener="#{groupBean.onRowSelect}" update="@all" />
如您所见,当点击一行时,selectedItem
设置为groupBen.goup
对象。
public void onRowSelect(SelectEvent event) {
if (prevGroupId == group.getId())
group = new PersonelGroup();
else
prevGroupId = group.getId();
}
在onRowSelect
方法中,您可以通过比较之前选择的项目ID来检查用户是否第二次点击同一行。通过将group
对象实例化为new,DataTable已更新为无选择状态。
重要的是不要忘记在DataTable中添加update="@all"
attiribute。