How to avoid unselection when selecting a single row in PrimeFaces datatable?

拈花ヽ惹草 提交于 2019-12-11 19:32:59

问题


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) Select one row. Result: "Person 2" added to selectedPeople.

List selectedPeople=["Person 2"]

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

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

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

List selectedPeople=["Person 3"]


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.


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



回答1:


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

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" />

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

Source: www.primefaces.org/docs/guide/primefaces_user_guide_5_2.pdf



来源:https://stackoverflow.com/questions/31709425/how-to-avoid-unselection-when-selecting-a-single-row-in-primefaces-datatable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!