Describe the bug
I have a table with grouping and selection enabled. I would like to achieve the following behavior:
- Non-grouped rows are selectable; selection is toggled via a checkbox on the row
- Grouped rows have selection checkboxes, but they don't have their own selection state
- the checkbox is checked if all sub rows are checked
- the checkbox is not checked is all subrows are unchecked
- the checkbox is indeterminate if some sub rows are checked
- interactively toggling the checkbox manually selects/deselects all sub rows
To get this behavior, I've configured my table as follows:
enableRowSelection: function that returns true for non-grouped rows and false for grouped rows
enableMultiRowSelection: true
enableSubRowSelection: true
- state of the checkbox for grouped rows is updated programmatically using
row.getIsAllSubRowsSelected() and row.getIsSomeSelected()
- interaction with checkbox for rows (both grouped and non-grouped) calls
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 from row.getIsSelected(). Calling toggleSelection(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:
- Expand a group
- Click the selection checkbox for the expanded group to mark it as selected
- See that all the subrows were selected (correct)
- Click the selection checkbox for the expanded group again to mark it as not selected
- Notice that nothing happened. The group and subrows remained selected when the desired behavior was for the group and subrows to all become not selected.
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 to true 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
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 returnstruefor non-grouped rows andfalsefor 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
falsefromrow.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
enableRowSelectionset totruefor 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