question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Datatable: support true Global Select/Deselect

See original GitHub issue

Description 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:closed
  • Created 3 years ago
  • Comments:37 (37 by maintainers)

github_iconTop GitHub Comments

1reaction
mellowarecommented, Jan 5, 2021

OK so lets get on the same page.

  1. Current PrimeFaces 8.0 behavior is the checkbox selects all on the current page.
  2. new attribute defaults to selectionPageOnly="true" which is exactly like PF 8.0 behavior out of the box.
  3. If you set selectionPageOnly="false" you are saying you want global selection of @all.
  4. Yes #3535 fixed a problem that was there either way if someone called the widget method 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.
1reaction
stolpcommented, Jan 3, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DataTables Group Select/Deselect - Stack Overflow
I am trying to figure out how to create a group select/deselect in datatables. Each row in the table ...
Read more >
Introduction to data.table
2022-11-15. This vignette introduces the data.table syntax, its general form, how to subset rows, select and compute on columns, and perform ...
Read more >
mui-datatables - npm
Start using mui-datatables in your project by running `npm i ... true, Show/hide the select all/deselect all checkbox header for selectable ...
Read more >
Data Tables - Lightning Design System
This class creates a table with formatted cells and allows you to use data table utilities. Accessibility#. Headers#. To create an accessible table,...
Read more >
Use sparklines to show data trends - Microsoft Support
Format a Sparkline chart · Select Line, Column, or Win/Loss to change the chart type. · Check Markers to highlight individual values in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found