How it works
Pinned cells use position sticky with offsets summed from the fixed widths of the pinned columns before them, and carry the card's surface so scrolled content passes underneath cleanly. The scroll position is read on scroll (once per frame) and a ResizeObserver; the root gets data-start while anything is hidden under the left pin and data-end while anything is hidden under the right pin, and each fades in a 14px shadow with a hairline on that edge. So at rest only the right edge shows a shadow, inviting a scroll, and at the far right only the left one does. Overscroll is contained so a sideways swipe does not navigate the page.
Use it for
- Wide data where the row label and a total must stay visible: months across a year, metrics across regions, plans across features.
Look elsewhere when
- Tables that fit their container: pinning adds nothing.
- Phones where only one or two columns would remain: show stacked cards instead.
Usage
import { PinnedColumnsTable } from './PinnedColumnsTable.jsx'
export function SalesByStore({ stores, months }) {
return (
<PinnedColumnsTable
title="Sales by store"
caption="Monthly sales by store"
rows={stores}
columns={[
{ key: 'name', title: 'Store', width: 140, pin: 'left' },
...months.map((m) => ({ key: m.key, title: m.label, width: 72, align: 'right' })),
{ key: 'total', title: 'Year', width: 88, align: 'right', pin: 'right' },
]}
/>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
columns | { key: string, title: ReactNode, width?: number, align?: 'left' | 'right', pin?: 'left' | 'right', render?: (row) => ReactNode }[] | — | Widths are fixed (120px by default) so pinned offsets add up exactly. Several columns can pin to each side; they stack in order. |
rows / rowKey | object[] / (row, i) => key | — | The data and a stable key per row; the first column is the row header. |
footer | Record<columnKey, ReactNode> | — | An optional totals row, pinned the same way. |
title / subtitle / caption / label | ReactNode / string | — | Heading, the table caption, and the name of the scrollable region (defaults to the caption). |
Accessibility
- The scroll area is a focusable region named after the caption, so keyboard users can scroll it with the arrow keys.
- It is a native table with column headers and row headers; pinning is purely visual and does not change reading order.
- The edge shadows are decorative hints; the caption or subtitle should say the table scrolls.
- Reduced motion makes the shadows appear without a fade.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
PinnedColumnsTable.jsxpinned-columns-table.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.





