Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Nested Rows Table Block for React

A headcount plan as a roll-up hierarchy of company, departments and teams, where every parent adds up its teams and a Depth toggle opens the plan to a level.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Show a hierarchy that adds up, with this nested rows table for React with Base UI. One company, three departments and seven teams sit in a single native table as a flat list where each unit knows its depth and its parent, so there is no recursive component. Only the teams carry figures: the headcount and budget of every department and of the company are the sum of the teams below it, worked out from the list whether the parent is open or folded. Depth shows in the indent, in the weight and tint of the row and in a hidden "Level 2" for a screen reader, and a chevron button opens and folds a parent. A Toggle Group in the summary strip (1, 2, All) opens the plan to that level, and shows none pressed once you have opened parents by hand. It's built from Toggle Group and Guides, with a CSS transition only. For headcount plans, budgets, org structures and any roll-up.

FAQ

How is a parent's total worked out?

Each unit is a row with an id, a parent and a depth; only the teams have figures. A small helper walks up from every team to the company and adds its headcount and budget to each unit on the way, so the totals follow any change to the data and the strip above the table, which reads the company row, always equals the sum of the teams.

What does the Depth toggle do?

1 shows only the company, 2 shows the company and its departments, and All shows every team. Opening or folding a parent by hand moves the plan to a depth that none of the three means, so the toggle then shows nothing pressed rather than claiming a depth it isn't at. The line over the table says how many of the rows are shown.

Why no recursive component?

A recursive row component and a recursive type work in React but break in the Vue and Svelte versions, so the plan is a flat list rendered by one map. Indentation comes from the depth, and a unit is shown when every unit above it is open, which a helper checks.

Is it accessible?

The table has a caption and column heads, each unit's name is its row header with "Level 2" read before it, and every parent's chevron is a button with aria-expanded and aria-controls, named with how many departments or teams it holds. After a press the focus returns to the same chevron, and the sums are read with "in total". Level is never carried by colour alone.

How does it look on a phone?

The Owner column folds under the unit's name, and Headcount and Budget stay in their own columns. The indent shrinks so a team's name still fits at 320 pixels, and the frame keeps the same height whichever depth is chosen.

What stays local, and how do I wire it for real?

The plan is typed in the file and the open parents are plain state, a list of ids. Nothing is saved or sent. Replace UNITS with your own units (keeping depth and parent in step), put figures on the leaves only, and keep the open list wherever you want it to survive a reload.

  • Pro

    Expandable Rows Table

    Rows that open

    A table of expense reports where a chevron button in each row opens its line items in a row beneath it, several at once, with one button that opens or folds them all.

  • Pro

    Grouped Rows Table

    Rows that open

    A pantry stock table regrouped by a Group by toggle (supplier, category or none), with group rows that fold, count their items, add up their value and stick under the column heads.

  • Pro

    Sortable Members Table

    Sort and search

    A members table whose column heads are buttons: press one to sort, again to reverse, a third time for the original order, with aria-sort on the active head, ties settled by name and a spoken line for each result.

  • Pro

    Sticky Header Table

    Columns and paging

    A sixty-row cash ledger in a fixed-height region where the column heads and the day row stay at the top while you scroll, with a Jump to menu of weeks that scrolls the region and a band that names the day at the top.

  • Pro

    Row Selection Table

    Select and act

    A stock list with a checkbox on every row, a head checkbox that shows a dash when only some are ticked, Shift-click range select and a live line that adds up the price of the ticked rows.

  • Pro

    File Explorer Table

    Rows that open

    A file explorer window with a rail of places, a path bar with an Up button, and a table that lists one folder at a time, folders first, with sortable heads and a New folder button.