shadcn.io is not affiliated with official shadcn/ui
Data Table examples · Advanced
Expandable Sub-Rows Data Table for React
A table of projects where each row expands to list the project's tasks.
Three projects, each with a chevron button that opens a panel of its tasks under the row: the task, who has it and its status. TanStack Table's row expanding keeps which rows are open. Use it for orders and their items, projects and their tasks, invoices and their lines: details that belong to a row but would crowd the table.
Preview
Installation
FAQ
How does a row expand?
getRowCanExpand is true when a project has tasks. The button calls row.getToggleExpandedHandler() and shows a down chevron while row.getIsExpanded() is true, a forward one otherwise. The forward chevron turns around in right-to-left layouts.
What is rendered under an open row?
A second TableRow whose single TableCell spans every column with colSpan. It holds a bg-muted/50 panel listing each task's name, assignee and status. The panel renders only while that row is expanded.
Which table features make expanding work?
tableFeatures includes rowExpandingFeature and expandedRowModel: createExpandedRowModel(). The tasks are a field on each project, not sub-rows, so the file passes no getSubRows.
Can a task expand again?
No. Tasks aren't table rows, so they have no expander. To nest rows, return the children from getSubRows and render the rows the expanded model returns.
Related
- Basic Data Table with CheckboxesA table of products with a checkbox on
- Data Table with ActionsA table of payments with a menu of
- Multi-Level Nested AccordionAn accordion of help center topics where
- Card CollapsibleA card with a Features header that
- Numeric Pagination Data TableA table of invoices with numbered page
- Data Table with FiltersA table of users with two inputs that