Do not unselect rows when clicking on another rows in Primefaces datatable

 ̄綄美尐妖づ 提交于 2019-12-24 16:17:42

问题


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 function clearSelection: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

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