问题
I'm working with Primefaces 3.5 Data Table. The table is with multiselection mode enabled. Basically, the table is the same as the last one from [this showcase][1]. So the table is defined like this
<p:dataTable id="myTable" var="item" value="#{myController.items}" selection="#{myController.selectedItems}" rowKey="#{item.id}">
<p:column selectionMode="multiple"/>
<p:column headerText="Id">
...
So when the user selects some rows by clicking on checkboxes and then accidentally clicks on one row, all selected rows become unselected except the one on which user clicked at last.
The question is: Is there any workaround to maintain rows selected even if user will click on the row out of checkbox?
Some of my observations:
- If the user will press Ctrl and click on the row all other rows will maintain selected. This behavior is exactly what I want, but without pressing Ctrl.
- I've looked at
primefaces.js
source and found that other rows are deselected by this functionclearSelection:function(){}
. It would be fine to do not execute it when user will click on row.
回答1:
If you read the more recent documentation, you can see it is supported in newer releases. So to fix this for 3.5, look at the source of the newer releases on how they 'fixed' this and create a js patch… You can ofcourse also try to use a newer PF version. Lots of advantages when doing the latter.
The reason for not posting (or even trying to create) a patch here (or trying to create one) is that it is waaaaay to complex to post here and imo beyond the scope of SO
回答2:
Copied from the question (which OP added there as an 'answer'):
As Kukeltje suggested, I've created primefaces.js
patch with modified DataTable
widget. To do so, I've copied primefaces.js
from jar file, performed modifications and put it under the following directory:
webapp
|-- META-INF
|-- WEB-INF
|-- resources
| |-- primefaces
| | `-- primefaces.js
The modification I've done in primefaces.js
was just removing this.unselectAllRows()
from onRowClick: function(e, d, a)
function.
来源:https://stackoverflow.com/questions/31591407/do-not-unselect-rows-when-clicking-on-another-rows-in-primefaces-datatable