primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Table checkbox selection ignores filtering

Open coffeymatt opened this issue 8 years ago • 15 comments

**I'm submitting a ...

[x ] bug report

Current behavior If you use table selection (https://www.primefaces.org/primeng/#/table/selection) and have a checkbox header to select all (p-tableHeaderCheckbox), selecting all will include filtered out rows and rows from other pages.

Expected behavior

When you select all, it shouldn't include in the selected data array, data that has been filtered out or is on another page. It should only select what's visible on the screen.

Minimal reproduction of the problem with instructions

Create a table with two pages of data and a basic filter and multi row selection with checkboxes as per the docs. Note that when you select all, items you have filtered out or are on another page are included in the selection.

What is the motivation / use case for changing the behavior?

It's the logical expected behaviour, only to select what you can see.

  • Angular version: 5.2.6

  • PrimeNG version: 5.2.0

  • Browser: all

  • Language: [all]

coffeymatt avatar Feb 26 '18 17:02 coffeymatt

+1

mousedown avatar Mar 05 '18 12:03 mousedown

Having the exact same issue. Is there a temporary fix that can be implemented with table selection?

mhaisley avatar Mar 05 '18 16:03 mhaisley

You would have to keep track of the current filters selected with onFilter() then manually remove them from the array set with [(selection)]=

mousedown avatar Mar 06 '18 11:03 mousedown

I'm having a similar issue. When I check the p-tableHeaderCheckbox I get all on page (in my case 20) and next i nav through pages I can select one off items and it adds to my total number of selected items. However as soon as I check the select all on page again it blows away my selected items and shows me only those 20. Same thing if i select all on page 1, go to page 2 and select all again...page 1 stuff is gone.

arjendevries avatar Mar 14 '18 23:03 arjendevries

Same behavioral issues here ... totally confusing feature if it does not work fully integrated with paging and filters.

gonzalodevops avatar Mar 15 '18 10:03 gonzalodevops

Anyone confirmed this in 5.2.4? The select all checkbox is now not responding for me.

mousedown avatar Mar 28 '18 22:03 mousedown

it's fixed in 5.2.4

chfiras avatar Apr 13 '18 22:04 chfiras

after filtering and select all with checkbox you cannot deselect all with the checkbox again that issue appear in the version 5.2.4

chfiras avatar Apr 13 '18 22:04 chfiras

In 5.2.4 the behavior appears to be different depending on if [headerCheckboxToggleAllPages] is "true" or "false". If true then the bug is still there and the check-all checkbox ignores filtering. If false, then the check-all checkbox appears to work correctly (clearing previously selected options and selecting all currently filtered options).

However, I am using the deprecated datatable: https://www.primefaces.org/primeng/#/datatable/selection

e01010100 avatar Apr 17 '18 14:04 e01010100

What should be the behaviour for the following situation :

  1. Select 4 rows
  2. Filter to display only 2 of the 4 rows selected
  3. => the 2 hidden rows should remain selected or not ?

JordanDurieux avatar Apr 19 '18 13:04 JordanDurieux

the 2 hidden rows not selected

chfiras avatar Apr 19 '18 13:04 chfiras

@chfiras p-table keep the selection, no matter what is filtered

JordanDurieux avatar Apr 19 '18 13:04 JordanDurieux

What should be the behaviour for the following situation : Select 4 rows Filter to display only 2 of the 4 rows selected => the 2 hidden rows should remain selected or not ?

In that case the 4 rows should remain selected as you took no extra action.

  1. Select All rows (4)
  2. Filter to display only two rows (both of which are still selected, including the two you can no longer see)
  3. Deselect all rows (0 now selected)
  4. Select all rows while filtering is still applied (2 rows selected)
  5. Clear filtering - all rows now shown (2 rows still selected)

e01010100 avatar Apr 19 '18 15:04 e01010100

you took no extra action

So the p-table doesn't actually maintain the selection if applied AFTER select all is selected, only before. To do this, we must keep track when 'select all' checkbox is applied, then deselect all, then select all programatically when the filter changes with via onFilter, or put the onus on the user.

Select all now works and respects filtering if used after filter, however I there is now a second (expected) feature for filtering to respect select all.

There is also another bug associated here. Check box is disabled, following a select all on a filtered collection.

  • Apply Filter
  • Select All
  • Not the select All checkbox is disabled.

mousedown avatar Apr 22 '18 10:04 mousedown

I handled it using this.dataSource.filteredData instead of this.dataSource.data. https://stackblitz.com/edit/angular-biuy85

FTello31 avatar Jun 08 '20 17:06 FTello31