Skip to content
InsightCharts

Search

Search guides and components

Data table

A restrained editorial table from rows and a column config: aligned tabular numbers, an optional in-cell bar, row highlight and click-to-sort headers.

Use when
When readers need to look up exact values, or compare a handful of entities across several measures with different units. Sort it by the column the caption refers to and highlight the row it names.
Avoid when
Showing a trend or a single comparison (use line chart or bar chart); more than about 7 columns or 30 rows without maxHeight.

Preview

Wind and solar supplied 67% of Denmark's electricity in 2024Electricity generation by country, 2024
Denmark67%23.1+1.2%
Portugal46%22.9+2.7%
Germany43%209.4+3.1%
Spain42%112.8+4.4%
Netherlands41%49.6+5.8%
Poland24%40.2−0.4%
France14%73.5+0.9%
Source: Ember (illustrative figures)

Composition

Used in

1 template uses data table.

Templates

1

A set of linked charts over one shared dataset that filter each other. It has a headline, a sentence of instructions with filter chips, a row of figures that recompute from the filtered rows, two to four charts and an optional detail table. It opens on selections the author chooses.

Installation

$ pnpm dlx shadcn@latest add @insightcharts/data-table

The CLI copies the source into your project and needs the @insightcharts registry in components.json; see installation. With the package, import it by name:

import { DataTable } from "insightcharts";

Examples

Scrolling, sticky header, compact

Twelve cities with a low-traffic centrePopulation in millions, liveability score out of 100, share of trips by bike
Vienna1.98201571.231%
Copenhagen0.66201278.549%
Amsterdam0.93201475.138%
Zurich0.44201180.327%
Helsinki0.67201669.822%
Munich1.51201866.419%
Oslo0.72201082.641%
Stockholm0.98201377.035%
Lyon0.52201961.3–
Ghent0.27201764.930%
Bologna0.39202058.712%
Ljubljana0.30200973.416%
Source: Illustrative data for the gallery

Default columns, no sorting

PlanSeatsPrice per seatAnnual discount
Starter5$8None
Team25$1210%
Enterprise250CustomNegotiated

Two highlighted rows, negative values

Revenue grew in 2 of 5 regions in the fourth quarter
North€4.8M+6.4%
South€4M−2.1%
East€2.2M−4.8%
West€5.1M−0.7%
Islands€640K+11.2%

Props

PropTypeDefaultDescription
rowsrequiredRow[]One object per row.
columns(string | { key, label?, format?, align?, bar?, sortable?, width? })[]Columns in order. Defaults to every key of the first row. Numeric columns are right-aligned.
captionstringThe table's title, as a real <caption>.
subtitlestringUnits and period, under the caption.
sourcestringShown under the table as "Source: ...".
highlightstring | number | (string | number)[]Rows to emphasise, matched on the first column (or highlightKey).
highlightKeystringField highlight matches against.
sort{ key, direction?: "asc" | "desc" }Initial sort.
sortablebooleantrueClick or press Enter on a header to sort; a third press restores the original order.
maxHeightnumber | stringHeight before the body scrolls under the sticky header.
density"comfortable" | "compact""comfortable"Row padding.