Learning path
Style the grid
Step 8 of 8
Change row height, style rows and columns by value, and let your shadcn theme tokens restyle the grid.
Before you start, sort and filter rows.
The grid paints with shadcn tokens. Its root uses bg-background, border-border, and rounded-md. So a change to your theme tokens recolors the grid in light and dark mode. This step uses props for the rest.
Set density and classes
Replace people-grid.tsx with this file. It keeps the toolbar, the header sort, and the undo of the earlier steps. It also sets a taller row, dims inactive rows, and adds a shadow:
"use client";
import {
DataGridBody,
DataGridHeader,
DataGridProvider,
DataGridRoot,
type GetRowClassName,
} from "@/components/data-grid/data-grid";
import {
DataGridColumnsMenu,
DataGridFilterMenu,
DataGridSearch,
DataGridToolbar,
} from "@/components/data-grid-toolbar/data-grid-toolbar";
import {
useDataGridState,
} from "@/components/data-grid-history/data-grid-history";
import { columns, type Person } from "./columns";
const people: Person[] = [
{ id: "1", name: "Ada Lovelace", age: 28, active: true },
{ id: "2", name: "Grace Hopper", age: 34, active: true },
{ id: "3", name: "Margaret Hamilton", age: 31, active: false },
];
const dimInactive: GetRowClassName<Person> = (person) =>
person.active ? undefined : "text-muted-foreground";
export function PeopleGrid() {
const grid = useDataGridState(people);
return (
<DataGridProvider
{...grid}
columns={columns}
headerClickBehavior="sort"
>
<DataGridToolbar>
<DataGridSearch />
<DataGridFilterMenu />
<DataGridColumnsMenu />
</DataGridToolbar>
<DataGridRoot
aria-label="Players"
className="h-96 shadow-sm"
density="comfortable"
getRowClassName={dimInactive}
>
<DataGridHeader />
<DataGridBody />
</DataGridRoot>
</DataGridProvider>
);
}Result: rows are 44 px high, Margaret Hamilton shows in the muted text color, and the grid has a shadow.
densitypicks a row height preset, andcomfortablegives rows 44 px. See Density and small screens for the other values androwHeight.classNamemerges after the built-in classes of the root, so your utility wins a conflict.getRowClassNametakes a row and its view index, the position of the row in the sorted and filtered list. It can be an inline function. Rows re-render only when it returns different classes for the rendered rows.cellClassName: "font-medium"on a column styles every cell of that column.headerClassNamestyles its header cell.
Where next:
- The server path loads rows from your API.
- The custom code path adds your own cell types and plugins.
- The task finder looks up a task.