Ir al contenido
Español
Tabla con columnas fijas viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

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.

Úsalo para

  • Wide data where the row label and a total must stay visible: months across a year, metrics across regions, plans across features.

Busca otra opción cuando

  • Tables that fit their container: pinning adds nothing.
  • Phones where only one or two columns would remain: show stacked cards instead.

Uso

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' },
      ]}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
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 / rowKeyobject[] / (row, i) => key—The data and a stable key per row; the first column is the row header.
footerRecord<columnKey, ReactNode>—An optional totals row, pinned the same way.
title / subtitle / caption / labelReactNode / string—Heading, the table caption, and the name of the scrollable region (defaults to the caption).

Accesibilidad

  • 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.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

PinnedColumnsTable.jsxpinned-columns-table.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Tablas
Tabla comparativa viene con Pro. La vista previa aparece al desbloquearlo.
Tabla con barras de datos viene con Pro. La vista previa aparece al desbloquearlo.