Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Grouped Rows Table Block for React

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.

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

Let people look at the same rows in different groups, with this grouped rows table for React with Base UI. A Toggle Group says Group by Supplier, Category or None, and one native table of fourteen pantry items regroups at once. Each group is a tbody that opens with a row spanning the table, a th with scope="colgroup" holding a button that folds it, the number of items and the group's value, added up from its rows. The group row sticks under the column heads while the frame scrolls, Expand all and Collapse all work on the groups of the mode you are in, and each mode remembers which of its groups you folded. The frame keeps its height, and all four columns stay on a phone because the group rows span them. It's built from Toggle Group, Button and Guides. For stock, menus, rosters and any list worth viewing more than one way.

FAQ

How does Group by work?

The items are typed once, each with a supplier and a category. Choosing a mode asks a helper for the groups of that mode, in the same rows, with the items inside each group sorted by name. None is one group with no row of its own, so the table is flat. The line under the table says how the rows are grouped and how many groups are folded.

Where do the group values come from?

They are worked out, never typed twice: the value of a group is the sum, in cents, of the values of its items, and the count beside it is the number of those items. Change an item and every group that holds it follows.

Does each mode really remember its folds?

Yes. The folded groups are kept for each mode separately: fold Branwell Produce under Supplier, switch to Category and fold Dairy, then switch back and Branwell Produce is still folded. Expand all and Collapse all change only the mode you are in, and with None, where there is nothing to fold, they answer in words instead of doing nothing.

What sticks when I scroll?

The column heads stick at the top of the frame and the group row of the group you are reading sticks directly under them, each on a solid background so the rows never show through. Scrolling happens inside the frame, which can be reached with Tab, so the page and the block keep their height.

Is it accessible?

The table has a caption, column heads and the item as each row header. A group row is a colgroup header with a button that has aria-expanded and aria-controls and is named with the group, its item count and its value. A folded group's rows are hidden from everyone, not just from the eye.

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

The stock is typed in the file and the folds are plain state, so nothing is saved or sent. Replace ITEMS, SUPPLIERS and CATEGORIES with your own; to group by something else, add a mode to MODES and a branch to groupsFor.

  • Pro

    Nested Rows Table

    Rows that open

    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.

  • 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

    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

    Chip Filters Table

    Sort and search

    A bug table beside a rail of chip filters for priority and status: chips in a group are or, the groups are and, every chip counts what it would show, and an empty state clears them all.

  • 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

    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.