table
table copied to clipboard
Issue with getIsSomeRowsSelected when using grouping
TanStack Table version
v8.20.1
Framework/Library version
React 18.3.1
Describe the bug and the steps to reproduce it
The return value of table.getIsSomeRowsSelected is inconsistent when using the grouping feature, sometimes returning an erroneous value. Might be related to https://github.com/TanStack/table/issues/4878 I think this issue might be caused by the grouped row being considered in the selected state object of the table, even if it not a "real" row coming from the dataset. The getIsSomeRowsSelected function checks if the total number of rows selected is less than the flat rows of the filtered row model. Flat rows only returns rows included in the dataset, grouped columns are not part of this array.
However, since the selection state is including the "fictional" gruped columns it becomes possible for the totalSelected variable to be greater than the flatRows length.
Maybe grouped columns should not be considered for the selected state, since they are not items in the data array. Clicking on it should toggle subrows without including the grouped column in the state.
Steps to reproduce
- Go to https://codesandbox.io/p/devbox/tanstack-grouping-and-selection-4kyzxd?workspaceId=a99c66fb-3472-4189-a44e-72c9121d3c0a
- Change the displayed rows to 50 to make testing easier
- Click on the fist icon on the Status column to group
- Click on the checkbox of the first grouped row to select all its children
- Expand other groups and select the other subrows one by one; do not select using the grouped parent row
- Notice that at some point the header checkbox gets unchecked instead of being indetermined
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
https://codesandbox.io/p/devbox/tanstack-grouping-and-selection-4kyzxd?workspaceId=a99c66fb-3472-4189-a44e-72c9121d3c0a
Screenshots or Videos (Optional)
https://github.com/user-attachments/assets/12b7ee9d-462e-4477-955e-a8b3d1bd95f8
Do you intend to try to help solve this bug with your own PR?
Maybe, I'll investigate and start debugging
Terms & Code of Conduct
- [X] I agree to follow this project's Code of Conduct
- [X] I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.