Table Data

Renders a table from a column definition and a set of rows.

IDTrackDurationPlaysPeakLast
track-01
Night DriveThe Meridians
03:42 · 128.4K plays
03:42128.4K
2m ago
track-02
Slow LightAda Reyes
04:18 · 96.8K plays
04:1896.8K
17m ago
track-03
Open WaterKestrel
02:56 · 74.2K plays
02:5674.2K
41m ago

Configurations

Supported configurations for this component.

Configurations

2 examples
Selected row
IDTrackDurationPlaysPeakLast
track-01
Night DriveThe Meridians
03:42 · 128.4K plays
03:42128.4K
2m ago
track-02
Slow LightAda Reyes
04:18 · 96.8K plays
04:1896.8K
17m ago
track-03
Open WaterKestrel
02:56 · 74.2K plays
02:5674.2K
41m ago
No selection
IDTrackDurationPlaysPeakLast
track-01
Night DriveThe Meridians
03:42 · 128.4K plays
03:42128.4K
2m ago
track-02
Slow LightAda Reyes
04:18 · 96.8K plays
04:1896.8K
17m ago
track-03
Open WaterKestrel
02:56 · 74.2K plays
02:5674.2K
41m ago

Add to your project

One command adds this component to your project.

1

Run the following command. New project? Run npx shadcn@latest init first to set up Tailwind and path aliases.

npx shadcn@latest add @aicanvas/••••••••••••

Light and dark both come with the install and follow the dark class on <html>, the shadcn dark mode setup (next-themes with attribute="class").

Props

Every prop this component accepts. Any other prop is forwarded to the underlying element.

PropTypeDefaultDescription
columnsArray<{key: string, header: React.ReactNode, width?: string|number, align?: 'left'|'center'|'right', hideBelow?: 'md', fold?: 'info'|'meta'|'none', infoValue?: (row: object) => React.ReactNode, primary?: boolean, color?: string|((row: object) => string), render?: (row: object) => React.ReactNode, sortable?: boolean, sortValue?: (row: object) => string|number}>DEFAULT_COLUMNSColumn definitions. `sortable` makes the header a sort control; `sortValue` supplies what to compare when the cell is visual or the raw field would sort wrong. `hideBelow:'md'` hides the column on phones; it then folds into the per-row info tooltip (`fold:'info'`, the default), the primary column's mobile sub-line (`fold:'meta'`), or nowhere (`fold:'none'`). `infoValue` supplies the textual value shown in a fold (use it for visual cells like meters); `render` is the desktop cell.
rowsArray<object>DEFAULT_ROWSRow objects consumed by the column definitions.
getRowKey(row: object) => string|numberDEFAULT_GET_ROW_KEYReturns a stable key for each row.
onRowClick(row: object) => voidDEFAULT_ON_ROW_CLICKRuns when a non-interactive area of a row is clicked.
selectedRowKeystring|number|nullnullKey of the current row, shown with an active measurement edge. Null or omitted marks no row.
selectablebooleanfalseAdds a leading checkbox column with a select-all in the header. Selection is controlled: pass `selectedKeys` and handle `onSelectionChange`.
selectedKeysArray<string|number>[]Keys of the currently selected rows. Only read when `selectable`.
onSelectionChange(keys: Array<string|number>) => void-Called with the next full selection whenever a row checkbox or the select-all is toggled.
defaultSort{key: string, dir: 'asc'|'desc'}-Column the table opens sorted by. Omit and every sortable header shows its neutral marker until the reader picks one — a table that arrives pre-sorted with no one having asked reads as a bug.
onSortChange(sort: {key: string, dir: 'asc'|'desc'}) => void-Called after each header click. The table sorts itself either way; this is for callers that mirror the state elsewhere.
layout'fixed'|'auto''fixed'Column sizing. `fixed` splits the width evenly (or by each column's `width`); `auto` lets the content set it, which a wide operational table needs.
dividersbooleantrueDraws the inset hairline under every row but the last. Set false for a table that separates its rows by rhythm alone; the header keeps its rule either way, since that one divides two different things rather than two rows of the same thing.
classNamestring''Additional CSS classes applied to the root element.
styleReact.CSSProperties{}Inline styles applied to the root element.

More Andromeda Pro components