1

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.
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
andriy
  • 4,074
  • 9
  • 44
  • 71
  • If you read the more recent documentation, you can see it is supported in newer releases. So look at the source of the newer releases on how they 'fixed' this and create a js patch for 3.5… easy… or use a newer PF version – Kukeltje Jul 24 '15 at 05:53
  • I was thinking about creating the patch of `primefaces.js` with modified `clearSelection:function(){}` function, but it don't seems like that it is the best solution. But, ya... if there is no other way to solve it I should consider it as a solution. Updating version is also not very suitable for me. Thanks. – andriy Jul 24 '15 at 07:45
  • If you create a patch, pleasepost it as an answer. If you don't,please copy my comment and make it an answer – Kukeltje Jul 24 '15 at 07:50
  • If there will not be any other answer in few days, I'll considerate creating the patch as correct response. So you can post it as an answer. I'm appreciating any help :) – andriy Jul 24 '15 at 08:06

2 Answers2

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

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
-1

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.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • No need to override the primefaces.js. You can override individual functions and leave the primefaces.js as is: https://stackoverflow.com/questions/27551493/how-do-i-find-and-or-override-javascript-in-primefaces-component-based-on-widget and https://stackoverflow.com/questions/39639532/override-a-method-from-a-primefaces-specific-widget – Kukeltje Aug 02 '18 at 11:30