You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unselect child row -> parent row go to indeterminate state
How often does this bug happen?
Every time
Screenshots or Videos
Platform
I tried it on
OS: macOS
browser: Chrome
But I don't think it is browser issue.
react-table version
7.7.12
TypeScript version
4.5.5
Additional context
No response
Terms & Code of Conduct
I agree to follow this project's Code of Conduct
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.
Hello Jony,
To be honest, I think that there is something missing on the row property, something like row toggle all rows selected properties. This way you could toggle all properties from that specific row + his sub rows.
Also, expanding + row selection is not properly connected and you cannot do what you are trying to do, maybe Tan can help us out here.
I've fixed this in a local fork. The issue stems from row selection functioning independently of parent row selection. In other words, the current implementation allows a parent row to be selected independently of its child rows. This doesn't align with what I expect from nested checkbox behavior, namely:
When all children are selected, the parent should be selected.
When only some children are selected, the parent should be indeterminate.
When no children are selected, the parent should be unselected.
The fixes below pertain to the RowSelection.ts feature.
row.toggleSelected=(value,opts)=>{constisSelected=row.getIsSelected()table.setRowSelection((old)=>{value=typeofvalue!=="undefined" ? value : !isSelectedif(row.getCanSelect()&&isSelected===value){returnold}constselectedRowIds={...old}mutateRowIsSelected(selectedRowIds,row.id,value,opts?.selectChildren??true,table,)// could also be enabled through a new config option.returnsyncParentRowSelection(row,selectedRowIds,table)})}
/** * When child rows are updated, the parent state is not properly synced. * Assumptions: * When all children are selected, the parent should be selected. * When only some children are selected, the parent should be indeterminate. * When no children are selected, the parent should be unselected. */functionsyncParentRowSelection<TDataextendsRowData>(row: Row<TData>,selection: RowSelectionState,table: Table<TData>,): RowSelectionState{constparentRow=row.getParentRow()if(!parentRow){returnselection}constselected=isRowSelected(parentRow,selection)constisAllSubRowsSelected=isSubRowSelected(parentRow,selection,table)==="all"if(isAllSubRowsSelected&&!selected){mutateRowIsSelected(selection,parentRow.id,true,false,table)}elseif(!isAllSubRowsSelected&&selected){mutateRowIsSelected(selection,parentRow.id,false,false,table)}returnsyncParentRowSelection(parentRow,selection,table)}
Activity
nelsonrds commentedon May 25, 2022
Hello Jony,
You are building the parent Checkbox with the wrong properties. You have to differentiate the selected rows from the "parent" selected rows.
So we have this:

This image was taken from here: https://codesandbox.io/s/summer-lake-2qklsp?file=/src/App.js with the fix.
Regards,
Nelson.
EDIT: This won't work if you add more rows, I just duplicated the toggle all rows selected props to the "parent" row:

Jonyberry commentedon May 26, 2022
Hi Nelson,
thanks for quick answer!
I updated my sandbox and also I added one more row. When I tried your fix my parent checkbox now selects all rows but it should select only subrows.
Have you got any other idea how to fix it?
nelsonrds commentedon May 26, 2022
Hello Jony,
To be honest, I think that there is something missing on the row property, something like row toggle all rows selected properties. This way you could toggle all properties from that specific row + his sub rows.
Also, expanding + row selection is not properly connected and you cannot do what you are trying to do, maybe Tan can help us out here.
Good luck Jony!
tannerlinsley commentedon May 29, 2022
Feel free to open a discussion or use the Discord for more help!
Jonyberry commentedon May 30, 2022
Alright, I create discussion here
itsmejoeeey commentedon Sep 4, 2023
When following the reproduction steps, this same issue is visible in the "Expanding" CodeSandbox example from the guide.
This issue seems to have the same/similar symptoms to these other issues: #4720 #4759 #4878 #4879
Could you please advise if we are missing something @tannerlinsley?
itsmejoeeey commentedon Sep 15, 2023
See my comment on the above linked discussion that outlines a way I managed to implement this sort of "cascading" behaviour.
VincEnterprise commentedon Dec 21, 2023
bump. I'm still waiting for a row selection that is leaf node only and cascading with proper indeterminate state for parent rows.
It seems alot of people expect this behavior:
#4298
#4349
#4720
#4759
#4878
#4879
https://github.com/trimble-oss/modus-web-components/issues/1672
R-Bower commentedon Jan 27, 2024
I've fixed this in a local fork. The issue stems from row selection functioning independently of parent row selection. In other words, the current implementation allows a parent row to be selected independently of its child rows. This doesn't align with what I expect from nested checkbox behavior, namely:
The fixes below pertain to the
RowSelection.tsfeature.