How to lift up 'toggleAllRowsSelected' to a parent component?
I have a table build with react-table with row selection enabled. So the user can check a box on each row to select that row. Now I have some buttons above the table to do things with selected rows like archive or delete. When those options are clicked, I want to deselect all the rows. However, those buttons are in a component above the table. I've only seen ways to call 'toggleAllRowsSelected' from the component with the table.
4 Replies
national-gold•2y ago
You can do this by using refs and useImperativeHandle
variable-limeOP•2y ago
You have no idea how helpful that was! I googled "useImperativeHandle ref tanstack table" and found this post: https://github.com/TanStack/table/issues/841#issuecomment-1492944507
GitHub
deselect all selected rows command · Issue #841 · TanStack/table
Version 6.8.0 I want to cancel/deselect all the selected rows on a button click, say CANCEL. How to achieve this?
variable-limeOP•2y ago
I used that code in my app and it worked!! 🙂
rising-crimson•2y ago
You could also use a portal in the table component and render it where you need it