问题
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