Grouped Table
shadcn-table-library/grouped-tableFreeBlock
Rows grouped by a column value with collapsible group headers and live subtotals via aggregationFn.
Install it
npx shadcn@latest add https://shad-table.dev/r/grouped-table.jsonSource
1'use client'23import type { ColumnDef } from '@tanstack/react-table'4import { ChevronRight } from 'lucide-react'56export type Order = {7 id: string8 customer: string9 category: string10 amount: number11 status: string12}1314const currency = (value: number) =>15 value.toLocaleString('en-US', { style: 'currency', currency: 'USD' })1617export const columns: ColumnDef<Order>[] = [18 {19 accessorKey: 'category',20 header: 'Category',21 cell: ({ row, cell, getValue }) => {22 if (cell.getIsGrouped()) {23 return (24 <button25 type="button"26 onClick={row.getToggleExpandedHandler()}27 className="flex items-center gap-1.5 font-medium"28 >29 <ChevronRight30 className={`h-3.5 w-3.5 transition-transform ${31 row.getIsExpanded() ? 'rotate-90' : ''32 }`}33 />34 {getValue() as string}35 <span className="font-normal text-muted-foreground">36 ({row.subRows.length})37 </span>38 </button>39 )40 }41 if (cell.getIsPlaceholder()) return null42 return <span className="pl-5">{getValue() as string}</span>43 },44 },45 {46 accessorKey: 'customer',47 header: 'Customer',48 cell: ({ cell, getValue }) =>49 cell.getIsAggregated() ? null : (getValue() as string),50 },51 {52 accessorKey: 'status',53 header: 'Status',54 cell: ({ cell, getValue }) =>55 cell.getIsAggregated() ? null : (getValue() as string),56 },57 {58 accessorKey: 'amount',59 header: 'Amount',60 aggregationFn: 'sum',61 cell: ({ cell, getValue }) => (62 <span className={cell.getIsAggregated() ? 'font-medium' : undefined}>63 {currency(getValue() as number)}64 </span>65 ),66 },67]
What it pulls in
npm packages
Other registry items
Files it writes
More from shadcn-table-library
All 18 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Icons Tableanimated-icons-table | shadcn-table-library | Blocks | Free | 2 deps · 9 files | |
| Comparison Tablecomparison-table | shadcn-table-library | Blocks | Free | 1 dep · 4 files | |
| Data Tabledata-table | shadcn-table-library | Blocks | Free | 1 dep · 4 files | |
| Density & Exportdensity-export-table | shadcn-table-library | Blocks | Free | 1 dep · 4 files | |
| Editable Tableeditable-table | shadcn-table-library | Blocks | Free | 1 dep · 3 files | |
| Heatmap Tableheatmap-table | shadcn-table-library | Blocks | Free | 1 dep · 4 files | |
| Summary / KPI Tablekpi-table | shadcn-table-library | Blocks | Free | 1 dep · 5 files | |
| Live Status Indicatorslive-status-table | shadcn-table-library | Blocks | Free | 1 dep · 4 files |
