Datatable: support true Global Select/Deselect
See original GitHub issueDescription The provided checkbox-based multiple selection model features a global selection checkbox in the table header.
This checkbox only applies to the currently displayed rows of the table. This will become apparent when paging is activated, so the checkbox example in the Primefaces showcase will not reveal this properly.
This is both counter-intuitive and cumbersome when using with large sets of data.
As an example, imagine having a bulk delete action you want to apply to several hundred rows of data.
Describe the solution you would like
A similar problem has also been resolved with the DataExporter component in the past. Here the boolean attribute pageOnly
lets the user choose between a page or data set oriented approach.
The envisioned solution should likewise add a new boolean attribute to the Datatable component (e.g. globalSelectPageOnly
). The default should be true
, to keep backwards compatibility. When set to false
, all entries of the table should be affected by global selection/deselection.
Additional context
It has been recommended in the past, that a solution using a toggleSelect
event listener can also take care of global selection behavior.
See https://stackoverflow.com/questions/22965320/select-all-in-datatable-jsf-primefaces and https://stackoverflow.com/questions/35085709/primefaces-datatable-select-all-with-paginator.
This is basically working, but an irritating glitch is still present.
When individually selecting all visible rows, the global selection checkbox will get activated that despite not all table entries are selected. So to the user it appears that all entries have been selected while only the rows currently displayed page are selected.
This issue has initially been discussed in the PrimeFaces forum here: https://forum.primefaces.org/viewtopic.php?f=3&t=64788
Example XHTML
Taken from the checkbox example in the Primefaces showcase:
<p:dataTable id="checkboxDT" var="car" value="#{dtSelectionView.cars6}"
paginator="true" rows="5"
selection="#{dtSelectionView.selectedCars}" rowKey="#{car.id}" style="margin-bottom:0">
<f:facet name="header">
Checkbox
</f:facet>
<p:column selectionMode="multiple" style="width:16px;text-align:center"/>
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
</p:dataTable>```
Issue Analytics
- State:
- Created 3 years ago
- Comments:37 (37 by maintainers)
Top GitHub Comments
OK so lets get on the same page.
selectionPageOnly="true"
which is exactly like PF 8.0 behavior out of the box.selectionPageOnly="false"
you are saying you want global selection of@all
.selectAllRows()
it was making it@all
but never removing it. So that bug was always there. All we did to fix #3535 was to if they unselect a row I remove@all
and just select the values on the page since there is NO way to know all the possible rowkeys.I like to add, that this is typically of no concern when you keep track of the selection state on the server side.
One can argue, that the DOM representation of the selection can not in any case be fully aware of the underlying model here.
I think this is fine from the user side of view.