Skip to content

Block 245 of 297

Data Table

A report table with auto right-aligned numeric columns, status badges, and a scrollable captioned layout.

Puck key
DataTableBlock
Export
dataTableBlock
React component
<DataTable />
Path
components/puck/data-table-block.tsx
Dependencies
None
License
MIT

About this block

When to use it, how to write for it, and what to change in the code.

What it's for

A report table in a card. Column headers are one comma-separated line and each row is one pipe-separated line, which makes both easy to bind to a P1 data source. Numeric columns right-align automatically, the first column becomes row headers, and one column can render as colored status badges. Wide tables scroll sideways on small screens.

  • Enrollment or attendance by branch, site or program
  • Grant deliverables with an On track / At risk status column
  • Budget lines or survey results
Writing the content
  • Write each row's Cells in column order separated by |, like Riverside | 1,204 | 12.5% | On track. Up to 50 rows.
  • Set Status column number (1 = first) to the column holding words like On track, At risk, Off track or Complete; other words get a neutral badge.
  • Write a one-sentence Caption on what the table shows. It prints under the table; if blank, screen readers get the title.
Accessibility
  • The markup is a real table with a caption, column header cells and the first column as row headers, so screen readers announce context with each value (WCAG 1.3.1).
  • The scroll container is a focusable, labeled region with a focus outline, so keyboard users can scroll a wide table.
  • Status badges print the status word as text beside the colored dot, so status does not rely on color (WCAG 1.4.1).
Customizing the code
  • Add or move status words in STATUS_WORDS, and change badge colors in the TONE map.
  • Row style switches between even-row striping and divider lines; edit even:bg-neutral-50 to change the stripe.

Editor fields

What content editors see in the P1 sidebar when they select this block.

  • Titletext
  • Heading levelselect
  • Period or subtitletext
  • Column headerstext
  • Rowsarray
  • Status column numbertext
  • Row styleradio
  • Captiontext
  • Footnotetext