Skip to main content

DataTable

ComplexData<co-data-table>

DataTable lists records with sorting, row selection with bulk actions, a row menu, expandable rows, empty and loading states, and pagination with rows per page.

import { DataTable } from 'health-components';

Examples​

Showcase​

Storybook

Selectable​

Storybook

Row Menu And Expand​

Storybook

With Toolbar​

Storybook

Empty​

Storybook

Loading​

Storybook

Without Pagination​

Storybook

Usage​

<DataTable rows={claims} rowKey="id" selectable pageSize={10}
columns={[{ key: "id", label: "Claim", sortable: true }, { key: "status", label: "Status", render: r => <StatusTag kind="claim" status={r.status} /> }]}
bulkActions={ids => <Button size="sm" onClick={() => resubmit(ids)}>Resubmit</Button>}
rowMenu={r => [{ label: "Open Claim", onSelect: () => open(r) }, { divider: true }, { label: "Void Claim", danger: true }]}
renderExpanded={r => <ClaimLines claim={r} />} />

When to use​

  • Any list of records staff work through: claims, PA queue, patients, appointments, audit log.

When not to use​

  • Two or three items: a list in a card.
  • Phone screens: list rows.

Variants and states​

VariantWhat it is
sortableHeader buttons with aria-sort.
selectableCheckbox column, select all on page (indeterminate), bulk bar "N selected" with actions and Clear selection.
row menuKebab per row.
expandableChevron column opens a detail row.
emptyMessage across all columns.
loadingSkeleton rows.
paginationRows per page 5, 10, 25, 50; Previous, Page N of M, Next.
densityCompact sets cell padding to 4px.

Accessibility​

  • Sort buttons sit inside th with aria-sort.
  • Row checkboxes are named after the first column ("Select CLM-20871").
  • Row menus are named "Actions for CLM-20871".
  • Numbers are right aligned with tabular figures.

Do and don't​

  • Do: Put the status column near the left so it is seen first.
  • Do: Keep row actions in the menu and the main action as a link on the record ID.
  • Don't: Horizontal scroll inside a modal.
  • Don't: Delete as the first item in a row menu.

Props​

PropTypeDefaultDescription
columns *ReadonlyArray<DataTableColumn<T>>—Array<{key, label, sortable?, align?, render?, sortValue?}>. Required
rows *ReadonlyArray<T>—The records. Required
rowKey(keyof T & string) | ((row: T) => DataTableRowId)"id"Field that identifies a row, or a function returning the id
selectablebooleanfalseRow checkboxes and a select-all-on-page checkbox
selectedDataTableRowId[]—Selected row ids (controlled)
defaultSelectedDataTableRowId[][]Initially selected row ids (uncontrolled)
onSelectedChange(ids: DataTableRowId[]) => voidnoneCalled with the new selected ids
bulkActions(selectedIds: DataTableRowId[]) => ReactNodenone(selectedIds) => node: actions shown in the bulk bar while rows are selected
rowMenu(row: T) => MenuItem[]none(row) => MenuItem[]: a kebab menu at the end of each row
renderExpanded(row: T) => ReactNodenone(row) => node: makes rows expandable
expandedDataTableRowId[]—Expanded row ids (controlled)
defaultExpandedDataTableRowId[][]Initially expanded row ids (uncontrolled)
onExpandedChange(ids: DataTableRowId[]) => voidnoneCalled with the new expanded ids
loadingbooleanfalseShows skeleton rows and hides pagination
emptyTextReactNode"No records match your search or filters."Text when there are no rows
emptyStateReactNodenoneNode when there are no rows (an EmptyState); wins over emptyText
pageSizenumber10Initial rows per page
pageSizesreadonly number[] | false[5, 10, 25, 50]Rows-per-page choices, or false to hide the selector
onPageSizeChange(size: number) => voidnoneCalled with the new rows per page
pagenumber—Current page, 1-based (controlled)
defaultPagenumber1Initial page (uncontrolled)
onPageChange(page: number) => voidnoneCalled with the new page
paginationbooleantruePaginate the rows
sortDataTableSort | null—Active sort (controlled); null for none
defaultSortDataTableSort | nullnoneInitial sort {key, dir} (uncontrolled)
onSortChange(sort: DataTableSort | null) => voidnoneCalled with the new sort
toolbarReactNodenoneToolbar above the table (search, filters); replaced by the bulk bar while rows are selected
captionstringnoneScreen reader caption

Also accepts native attributes, including defaultChecked, defaultValue, autoFocus, onInput, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-data-table>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-data-table selectable loading [columns]="columns" (co-selected-change)="onSelectedChange($event.detail)"></co-data-table>
KindNameDescription
property / JSON attributecolumnsArray<{key, label, sortable?, align?, render?, sortValue?}>. Required
property / JSON attributerowsThe records. Required
property / JSON attributerow-key / rowKeyField that identifies a row, or a function returning the id; default "id"
attributeselectableRow checkboxes and a select-all-on-page checkbox; default false
property / JSON attributeselectedSelected row ids (controlled)
property / JSON attributedefault-selected / defaultSelectedInitially selected row ids (uncontrolled); default []
property / JSON attributeexpandedExpanded row ids (controlled)
property / JSON attributedefault-expanded / defaultExpandedInitially expanded row ids (uncontrolled); default []
attributeloadingShows skeleton rows and hides pagination; default false
attributepage-size / pageSizeInitial rows per page; default 10
property / JSON attributepage-sizes / pageSizesRows-per-page choices, or false to hide the selector; default [5, 10, 25, 50]
attributepageCurrent page, 1-based (controlled)
attributedefault-page / defaultPageInitial page (uncontrolled); default 1
attributepaginationPaginate the rows; default true
property / JSON attributesortActive sort (controlled); null for none
property / JSON attributedefault-sort / defaultSortInitial sort {key, dir} (uncontrolled); default none
attributecaptionScreen reader caption; default none
attributedefault-checked / defaultChecked
property / JSON attributedefault-value / defaultValue
attributeauto-focus / autoFocus
property (function)rowMenu(row) => MenuItem[]: a kebab menu at the end of each row; default none
eventco-selected-changeCalled with the new selected ids; default none (React: onSelectedChange)
eventco-expanded-changeCalled with the new expanded ids; default none (React: onExpandedChange)
eventco-page-size-changeCalled with the new rows per page; default none (React: onPageSizeChange)
eventco-page-changeCalled with the new page; default none (React: onPageChange)
eventco-sort-changeCalled with the new sort; default none (React: onSortChange)
eventco-input (React: onInput)
slotbulk-actions(selectedIds) => node: actions shown in the bulk bar while rows are selected; default none Plain text also works as the `bulk-actions` attribute.
slotrender-expanded(row) => node: makes rows expandable; default none Plain text also works as the `render-expanded` attribute.
slotempty-textText when there are no rows; default "No records match your search or filters." Plain text also works as the `empty-text` attribute.
slotempty-stateNode when there are no rows (an EmptyState); wins over emptyText; default none Plain text also works as the `empty-state` attribute.
slottoolbarToolbar above the table (search, filters); replaced by the bulk bar while rows are selected; default none Plain text also works as the `toolbar` attribute.