# Shadcn Sub Table

> Data grid with sub table

- Type: example, free and open source (MIT)
- Component: [Data Grid](https://reui.io/components/data-grid.md)
- Page: https://reui.io/components/data-grid/c-data-grid-9
- Docs (Base UI): https://reui.io/docs/components/base/data-grid.md
- Docs (Radix UI): https://reui.io/docs/components/radix/data-grid.md
- MCP: `get_example("c-data-grid-9")`
- Registry item: https://reui.io/r/styles/base-nova/c-data-grid-9.json
- Uses: Avatar, Badge, Button, Card, Data Grid

## Best for

Order rows that expand into a nested grid of line items, each with its own sorting and paging

## Agent notes

- Each expanded order mounts `OrderItemsSubTable`, a separate `DataGrid` and `useTable` over that order's `items`, so its sort and page state are its own

## When not to use

- A short line of text under a row rather than a nested list: use [Expandable Rows](https://reui.io/components/data-grid/c-data-grid-8.md) (`get_example("c-data-grid-8")`)

## Third-party libraries

- TanStack Table v9: [API reference](https://tanstack.com/table/v9/docs/framework/react/reference/index), [docs](https://tanstack.com/table/v9/docs/framework/react/quick-start)
- Class Variance Authority: [API reference](https://cva.style/api-reference/), [docs](https://cva.style/)

## Install

```bash
npx shadcn@latest add @reui/c-data-grid-9
```

## About Shadcn Data Grid

### When to use

- Admin and back office tables that sort, filter, paginate and select rows
- Spreadsheet style editing with cell selection, clipboard and inline edits
- Large record sets that need virtualized rows, columns or infinite scroll

### When not to use

- A short static list of rows with no sorting or paging: use [Table](https://reui.io/components/table.md) (`get_component("table")`)
- Records moved as cards between status columns: use [Kanban](https://reui.io/components/kanban.md) (`get_component("kanban")`)
- A folder or category hierarchy with no columns of data: use [Tree](https://reui.io/components/tree.md) (`get_component("tree")`)

### Agent notes

- With `manualPagination`, pass the server total to `useTable` as `rowCount` as well as `recordCount`, or the page buttons never render
- Give `useTable` a stable `getRowId` whenever rows can be pinned, reordered or virtualized
- Swap `DataGridTable` for `DataGridTableVirtual` when rows need virtualization or infinite scroll

Every ReUI item has a twin like this one; the index is https://reui.io/llms.txt. Agents with the ReUI MCP (https://reui.io/docs/mcp) get the same guidance from the getters named above.
