-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot toggle selection of grouped row to deselect its children #4759
Comments
I see this issue reproduced in your sandbox, but I have yet to be able to reproduce this issue anywhere else. And actually, after modifying your sandbox a bit, I was able to solve the bug by just using the built-in https://codesandbox.io/p/sandbox/priceless-swanson-cc7w0c?file=%2Fsrc%2Fmain.tsx I'll need to look more into this to see if the change here is necessary. |
@KevinVandy Thanks for looking into this. The solution you mentioned of using In a sense, what I am looking for is a way to have a group selection checkbox that behaves exactly like a selection checkbox for the entire table:
I am open to alternative suggestions of how to achieve this behavior. For example, would you be more receptive to a more focused function on a row whose entire purpose is to toggle the selection of subrows? An approach like that would mirror the |
I'm fully with @mollykreis , also see this issue: |
bump, any news on this? |
bump |
try the following: <IndeterminateCheckbox
{...{
checked: row.getIsAllSubRowsSelected(),
indeterminate: row.getIsSomeSelected(),
onChange: () =>
row.subRows.forEach((subRow) =>
subRow.toggleSelected(
!row.getIsAllSubRowsSelected(),
),
),
}}
/> |
Describe the bug
I have a table with grouping and selection enabled. I would like to achieve the following behavior:
To get this behavior, I've configured my table as follows:
enableRowSelection
: function that returnstrue
for non-grouped rows andfalse
for grouped rowsenableMultiRowSelection
: trueenableSubRowSelection
: truerow.getIsAllSubRowsSelected()
androw.getIsSomeSelected()
row.toggleSelected(newCheckboxState)
Problem:
Interactively trying to uncheck a grouped row's checkbox does nothing when it should deselect all the rows beneath it. The problem is that the grouped row will always return
false
fromrow.getIsSelected()
. CallingtoggleSelection(false)
on this grouped row, which should deselect all the sub rows, returns early because it detects that the row is already not selected so there is nothing to be done to deselect it.Your minimal, reproducible example
https://codesandbox.io/p/sandbox/crimson-river-2ysx73
Steps to reproduce
In the code sandbox:
Expected behavior
I expected to create a grouped row whose selection is based only on the selection of its subrows. Clicking the checkbox associated with that grouped row toggles the selection for all of its subrows.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Not platform specific
react-table version
8.7.9
TypeScript version
No response
Additional context
As a note, I also went down an implementation path where I had
enableRowSelection
set totrue
for both grouped rows and non-grouped rows. However, this also did not lead to the behavior I wanted. The primary problem I encountered was that I didn't want a group's selection state to be part of TanStack's row selection state because the group's selection state is always determined programmatically by the state of its subrows.Terms & Code of Conduct
The text was updated successfully, but these errors were encountered: