how to allow only table to expand one row at a time #5589
Unanswered
linaffilomania
asked this question in
Q&A
Replies: 3 comments 2 replies
-
this allows limiting main rows to only 1 open but allows normal expand logic in sub rows onClick: () => {
const state = table.getState();
const expanded = structuredClone(state.expanded) as Record<
string,
boolean
>;
if (row.id.includes('.')) {
expanded[row.id] = !row.getIsExpanded();
table.setExpanded(expanded);
return;
}
table.setExpanded(row.getIsExpanded()?{}:{ [row.id]: true });
// return row.getToggleExpandedHandler();
}, |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is what I do: onClick: () => table.setExpanded({ [row.id]: !row.getIsExpanded() }), //only 1 detail panel open at a time ^Above advice is about the same and good too. Let's leave issues for bugs and convert this into a discussion |
Beta Was this translation helpful? Give feedback.
1 reply
-
This is what i do: const [expanded, setExpanded] = useState<ExpandedState>({})
const table = useReactTable({
data,
columns,
enableRowSelection: true,
enableExpanding: true,
getCoreRowModel: getCoreRowModel(),
getExpandedRowModel: getExpandedRowModel(),
getRowCanExpand: () => true,
state: {
expanded,
},
onExpandedChange: (newExpanded) => {
const nextExpanded = typeof newExpanded === 'function' ? newExpanded({}) : newExpanded
setExpanded(Object.keys(expanded)[0] === Object.keys(nextExpanded)[0] ? {} : nextExpanded)
},
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
TanStack Table version
e.g. @tanstack/react-table": "^8.11.0
Framework/Library version
e.g. React 18.2.0
Describe the bug and the steps to reproduce it
how i can that just one expand will be open
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
.
Screenshots or Videos (Optional)
.
Do you intend to try to help solve this bug with your own PR?
None
Terms & Code of Conduct
Beta Was this translation helpful? Give feedback.
All reactions