Power-User Systems

Data Grid

A virtualised grid over thousands of rows: resizable columns, multi-key sorting, range selection and keyboard navigation. Header and body share one scroller so they can never desync, selection is keyed by row id so it survives a re-sort, and focus stays on the viewport so a recycled row can never take the arrow keys down with it. Give it a parent with a bounded height — like every windowing implementation, in an auto-height parent it quietly stops windowing and renders every row.

Install

bun add lucide-react clsx tailwind-merge

Then copy 10 files into your project:

  • components/registry/data-grid/data-grid.tsx
  • components/registry/data-grid/types.ts
  • components/registry/data-grid/util.ts
  • components/registry/data-grid/use-columns.ts
  • components/registry/data-grid/use-virtual-rows.ts
  • components/registry/data-grid/header-row.tsx
  • components/registry/data-grid/body-rows.tsx
  • components/registry/data-grid/skeleton-rows.tsx
  • lib/utils.ts
  • hooks/use-animation-loop.ts

Props

PropTypeDefaultDescription
rowHeightnumber34Height of one row. Fixed rather than measured, and that is the whole performance story — a constant height makes the first visible row a division instead of a search, so scrolling to row 90,000 costs exactly what scrolling to row 3 costs.
headerHeightnumber34Height of the header. It shares the body's scroller, so this is also the offset the window calculation has to subtract from `scrollTop` — get it wrong and the rendered slice lags the scroll by exactly one header.
overscannumber6Extra rows rendered above and below the fold. At 0 you can out-scroll the renderer and see white bands at the leading edge; past about fifteen you are paying for rows nobody will reach before they are recycled.
minColumnWidthnumber80Floor a column can be dragged to. Without one a column can be collapsed to nothing and then cannot be grabbed again, because the handle it would be grabbed by has no width either.
stickyHeaderbooleantruePin the header while the body scrolls. It sits inside the same scroller rather than in a second one kept in sync by hand — that synchronisation is never actually synchronous, and the header lagging the body on a fast horizontal flick is its signature.
resizableColumnsbooleantrueAllow dragging column edges. The handle is a sibling of the sort button, not a child: nested, every resize would end by firing a click on the header and re-sorting the grid you were only trying to widen.
sortablebooleantrueAllow clicking a header to sort. The cycle has three states — ascending, descending, unsorted — because without the third there is no way back to the order the data arrived in, and for a feed that is most-recent-first one click destroys it permanently.
multiSortbooleantrueShift-click a second header to sort by it as a tiebreak. The rank is printed beside each arrow: two arrows with no numbers do not say which key is primary, and that is the entire difference between two different orderings.
selectionMode"none" | "single" | "range""range"How rows may be selected. Range adds Shift-click for a span and Ctrl/Cmd-click for a toggle, both anchored the same way the keyboard's Shift+Arrow is — one code path, so the two can never disagree about what is selected.
zebrabooleantrueBand alternate rows. Computed from the absolute row index rather than from the position inside the rendered window, which is what stops the stripes from crawling as you scroll.
showSkeletonbooleanfalseRender placeholder rows instead of data. They hold the exact row height and column widths the real rows will, so nothing moves when the data lands — a spinner in an empty box only promises a wait, and then rearranges the page at the end of it.
accentstring (hex)"#a855f7"Selection wash, the active-row marker down the left edge, and the colour a sorted header takes.

What It Demonstrates

Skeleton / Shimmer
A placeholder with a moving sheen shown while content loads.
Layout thrashing
Animating properties like width, height, top, or left that force the browser to recalculate layout every frame, causing jank.
Frame rate (FPS)
Frames drawn per second. 60fps is the baseline for smooth motion; 120fps on newer displays.
Spatial consistency
Animating so an element keeps its identity and position across states, so users never lose track of where things went.
Frequency of use
The more often a user sees an animation, the shorter and subtler it should be.

Related Components

Appears In