在PrimeFaces数据表中选择单行时如何避免取消选择? [英] How to avoid unselection when selecting a single row in PrimeFaces datatable?

查看:91
本文介绍了在PrimeFaces数据表中选择单行时如何避免取消选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以列表people = ["Person 1","Person 2","Person 3"]为例,并使用一个名为selectedPeople的空列表,必须执行以下步骤:

Using the list people=["Person 1", "Person 2", "Person 3"] as example, and an empty list called selectedPeople, the following steps must be done:

1)选择一行.结果:个人2"已添加到selectedPeople.

1) Select one row. Result: "Person 2" added to selectedPeople.

列表selectedPeople = [人员2"]

List selectedPeople=["Person 2"]

2)选择另一行.结果:个人3"已添加到selectedPeople.

2) Select another row. Result: "Person 3" added to selectedPeople.

列表selectedPeople = [人员2",人员3"]

List selectedPeople=["Person 2", "Person 3"]

3)仅选择这些行之一.结果:从selectedPeople中删除了人2".

3) Select only one of these rows. Result: "Person 2" removed from selectedPeople.

列表selectedPeople = ["Person 3"]

List selectedPeople=["Person 3"]

问题:PrimeFaces的dataTable的默认行为是,如果我单击其他选定行,则取消选择其他选定行.告诉用户按住Ctrl或Shift键以选择表中的许多记录不是最好的事情.

Issue: the default behavior of PrimeFaces' dataTable is to unselect other selected rows if I single-click one of them. It's not the best thing to tell users to hold Ctrl or Shift keys to select many records in a table.

到目前为止,我所做的是: http://pastebin.com/qHvnZPiY

What I've done until now: http://pastebin.com/qHvnZPiY

推荐答案

为避免取消选择,只需使用属性rowSelectMode="add"(但如果要取消选择它,则需要使用ctrl + click)

To avoid unselection, simply use attribute rowSelectMode="add" (but if you want it to be unselected, you need to use ctrl+click)

我们最后使用的解决方案是放置rowSelectMode="checkbox",以便仅当我单击第一列<p:column selectionMode="multiple" />

The solution we used in the end is to put rowSelectMode="checkbox" so the row is selected only when I click the first column <p:column selectionMode="multiple" />

然后将侦听器用于事件toggleSelectrowSelectCheckboxrowUnselectCheckbox.

Then used the listeners for events toggleSelect, rowSelectCheckbox and rowUnselectCheckbox.

来源:www.primefaces.org/docs /guide/primefaces_user_guide_5_2.pdf

这篇关于在PrimeFaces数据表中选择单行时如何避免取消选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆