Skip to content

Data Table

Last updated 28 Nov 2026

NbDataTable is a presentational, data-driven table for read-mostly application lists. It ships full <table> semantics, controlled sorting, row selection, loading / empty / error states, density options, a sticky header with horizontal scroll, and a companion NbPagination footer.

The canonical layout ​

This is the table to start from. It follows the anatomy of Carbon's data table: the title and an optional description sit at the top left, the toolbar runs along the right underneath them, and the one primary action (here, "New") is the last button in the toolbar, flush in its corner and as tall as the toolbar. Actions on a single row go at the end of that row.

Put the title, the description and the primary button on the table, not around it. A heading and a button laid out above a table, or a panel wrapped around it, duplicate what the table already draws, and the table paints its own surface, so it needs no box.

vue
<template>
  <NbDataTable
    :columns="columns"
    :rows="rows"
    row-key="id"
    title="Team members"
    description="People with access to this workspace."
    :row-actions="rowActions"
  >
    <template #toolbar-actions>
      <NbButton variant="primary" icon="plus" @click="create">New</NbButton>
    </template>
  </NbDataTable>
</template>

The table takes care of the measurements, so there is nothing to size by hand:

  • Title in the heading-02 type set (Carbon's 20px heading-03), with 16px above it, 24px below and 16px at the sides. The description is body-md in --nb-c-text-muted.
  • Toolbar as tall as a row, from 32px to 48px. It is an NbToolbar, flush: buttons in it without a size of their own take its height and lose their corners.
  • Header in the heading-compact type set (14/18 semibold) on a fill one step deeper than the table, with no rule under it.
  • Rows in body-md (14px regular) and --nb-c-text-muted, a rule under each one and none between columns. A hovered or selected row lifts its text to --nb-c-text.
  • No box. The table paints its layer and stops there: no border around it.

Basic Usage ​

Provide columns, rows, and a rowKey for identity. Cell values are read from row[column.key] by default.

vue
<template>
  <NbDataTable :columns="columns" :rows="rows" row-key="id" />
</template>

<script setup lang="ts">
import type { IDataTableColumn } from '@nubisco/ui'

interface Member {
  id: number
  name: string
  role: string
  status: string
}

const columns: IDataTableColumn<Member>[] = [
  { key: 'name', header: 'Name', sortable: true },
  { key: 'role', header: 'Role', sortable: true },
  { key: 'status', header: 'Status', align: 'center' },
]

const rows: Member[] = [
  { id: 1, name: 'Ada Lovelace', role: 'Engineer', status: 'Active' },
  { id: 2, name: 'Grace Hopper', role: 'Admiral', status: 'Active' },
  { id: 3, name: 'Alan Turing', role: 'Researcher', status: 'Away' },
]
</script>

Sorting ​

Sorting is controlled: the table renders the sortState you pass and emits a sort event with the next state when a sortable header is activated (click or keyboard). Direction cycles asc → desc → none. Apply the ordering yourself (or server-side) so the component stays honest about what it displays. Sortable headers expose aria-sort.

vue
<template>
  <NbDataTable
    :columns="columns"
    :rows="sortedRows"
    row-key="id"
    :sort-state="sortState"
    @sort="onSort"
  />
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'
import type { IDataTableSortState } from '@nubisco/ui'

const sortState = ref<IDataTableSortState>({ key: 'name', direction: 'asc' })

function onSort(state: IDataTableSortState) {
  sortState.value = state
}

const sortedRows = computed(() => {
  const { key, direction } = sortState.value
  if (direction === 'none') return rows
  return [...rows].sort((a, b) => {
    const cmp = String(a[key]).localeCompare(String(b[key]))
    return direction === 'asc' ? cmp : -cmp
  })
})
</script>

Selection ​

Set selectable to 'single' or 'multiple' to render a leading control column, and bind the selected row keys with v-model:selected. The header "select all" checkbox (multiple mode) reflects an indeterminate state and preserves selections that live on other pages.

vue
<template>
  <NbDataTable
    :columns="columns"
    :rows="rows"
    row-key="id"
    selectable="multiple"
    v-model:selected="selected"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue'

const selected = ref<(string | number)[]>([])
</script>

Toolbar, batch actions & row actions ​

The toolbar has two rows. The first holds the title and description (or your own #toolbar content). The second is the strip of tools: a #search slot that takes the spare width, then the #toolbar-actions slot along the right. Each row renders only when it has something in it. While rows are selected, a batch-action bar covers the strip of tools, not the title, and renders the #batch-actions slot (with a clear helper). The strip keeps its height either way, so nothing below it moves. The batch bar is an NbBatchActions overlay, with Cancel on the far right, and while it is up every row action is disabled. A trailing actions column appears whenever rowActions or a #row-actions slot is provided.

rowActions is the way to give rows actions. It returns the row's actions as IActionGroupItems, rendered as small ghost icon buttons whose label is their name and tooltip. Return the same actions for every row: one that does not apply stays in place with disabled and a disabledReason, which its tooltip reads out. Past three, two stay and the rest go into an NbOverflowMenu, where a disabled action keeps its reason as a second line under its label and the arrow keys still stop on it. The #row-actions slot is still there for anything else, and gets disabled while the batch bar is up.

ts
function rowActions(row: Member): IActionGroupItem[] {
  return [
    {
      id: 'edit',
      label: 'Edit',
      icon: 'pencil-simple',
      onSelect: () => edit(row),
    },
    {
      id: 'remove',
      label: 'Remove',
      icon: 'trash',
      disabled: row.status === 'Away',
      disabledReason: 'Away members cannot be removed',
      onSelect: () => remove(row),
    },
  ]
}
vue
<NbDataTable
  :columns="columns"
  :rows="rows"
  row-key="id"
  title="Team members"
  description="People with access to this workspace."
  selectable="multiple"
  v-model:selected="selected"
  :row-actions="rowActions"
>
  <template #toolbar-actions>
    <NbButton variant="primary" icon="plus">Add member</NbButton>
  </template>
  <template #batch-actions="{ selectedKeys, clear }">
    <NbButton variant="primary" icon="trash" @click="clear">
      Delete {{ selectedKeys.length }}
    </NbButton>
  </template>
</NbDataTable>

A toolbar that does not fit ​

The title always has a line of its own, so only the strip of tools can run out of room. When it does, the #search field moves to a line of its own above the buttons, which stay at the end. This follows the table's own width, not the screen's, so a table in a card or a side panel wraps the same way a phone does. Tick a row: the batch bar still covers the whole strip, at whatever height it has.

Filters go in #search too, as its direct children: a search field, a select or two, a date range. On a desktop they share the start of the strip. On a phone that line is too short for more than one field, so there they stack, each the full width of the table, 8px apart. A wrapper of your own around them is a single child, and its layout stays yours.

Custom cells ​

Render custom cell content three ways, in precedence order: a #cell-<key> slot, a column render function, then the raw value. Headers can be overridden with a #header-<key> slot.

vue
<template>
  <NbDataTable :columns="columns" :rows="rows" row-key="id">
    <!-- Slot approach: full template control -->
    <template #cell-status="{ value }">
      <NbBadge>{{ value }}</NbBadge>
    </template>
  </NbDataTable>
</template>

<script setup lang="ts">
import { h } from 'vue'
import type { IDataTableColumn } from '@nubisco/ui'

// Render-function approach: keep the definition next to the column
const columns: IDataTableColumn[] = [
  { key: 'name', header: 'Name' },
  {
    key: 'email',
    header: 'Email',
    render: (row) => h('a', { href: `mailto:${row.email}` }, row.email),
  },
  { key: 'status', header: 'Status' },
]
</script>

States ​

Loading renders shimmering skeleton rows (skeletonRows controls the count). error shows an error row that takes precedence over the empty state. When there are no rows, emptyMessage (or the #empty slot) is shown.

vue
<NbDataTable
  :columns="columns"
  :rows="rows"
  row-key="id"
  loading
  :skeleton-rows="5"
/>
<NbDataTable
  :columns="columns"
  :rows="rows"
  row-key="id"
  empty-message="No members yet"
/>
<NbDataTable
  :columns="columns"
  :rows="rows"
  row-key="id"
  error="Failed to load members."
/>

Density ​

size sets the row height on Carbon's scale. The header row matches it, and so do the toolbar and the batch bar, from 32px up to 48px. Cell padding (16px) and type (14px) stay the same at every size. Combine with zebra for alternating row backgrounds.

SizeRow heightUse it for
xs24pxVery dense lists inside another component
sm32pxDense lists, settings tables
md40pxCompact pages
lg (default)48pxMost tables
xl64pxRows with two lines of content, top-aligned

Before 5.37 the scale was sm 32px, md 48px (the default) and lg 64px. A table that never set size keeps its 48px rows. One that asked for md or lg by name is now 40px or 48px: ask for lg or xl to keep the old height.

vue
<NbDataTable :columns="columns" :rows="rows" row-key="id" size="sm" zebra />

Pagination ​

Drop an NbPagination into the #footer slot. Both components are fully controlled, so the same wiring drives client-side slicing or server-side paging. On page-size change the page resets to 1.

vue
<template>
  <NbDataTable :columns="columns" :rows="pagedRows" row-key="id">
    <template #footer>
      <NbPagination
        :page="page"
        :page-size="pageSize"
        :total="allRows.length"
        v-model:page="page"
        @update:page-size="onPageSize"
      />
    </template>
  </NbDataTable>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'

const page = ref(1)
const pageSize = ref(5)

function onPageSize(size: number) {
  pageSize.value = size
  page.value = 1
}

const pagedRows = computed(() => {
  const start = (page.value - 1) * pageSize.value
  return allRows.slice(start, start + pageSize.value)
})
</script>

Fill height & internal scroll ​

Set fill and the table becomes a flex item that fills its parent and scrolls internally: the toolbar and the #footer stay pinned, the header stays sticky, and only the body scrolls. This is the shape you want for a full-height list view, and it needs no table-specific CSS on your side.

vue
<template>
  <NbDataTable
    :columns="columns"
    :rows="rows"
    row-key="id"
    title="Team members"
    fill
  >
    <template #footer>
      <NbPagination v-model:page="page" :page-size="pageSize" :total="total" />
    </template>
  </NbDataTable>
</template>

The parent must bound the height ​

fill makes the table claim its parent's height. It cannot create one. The parent has to be a flex column that is itself bounded, which in practice means min-height: 0 somewhere up the chain. Without that, the parent grows to fit every row and the page scrolls instead of the body.

NbShell's content row already qualifies, so a table placed directly in #content works with no extra CSS:

scss
// Already part of NbShell, shown here for reference.
.nb-shell__content-row {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
vue
<NbShell>
  <template #content>
    <NbDataTable :columns="columns" :rows="rows" row-key="id" fill />
  </template>
</NbShell>

An unbounded wrapper between the shell and the table defeats it. A plain <div> grows to fit its content, so the table inherits no ceiling:

vue
<!-- Does not scroll internally: the wrapper has no bounded height. -->
<template #content>
  <div class="my-view">
    <NbDataTable :columns="columns" :rows="rows" row-key="id" fill />
  </div>
</template>

Give that wrapper the same treatment and it works again:

scss
.my-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

Leave fill off (the default) and the table sizes to its content exactly as before.

Stacked on a phone ​

Set stackOnPhone and, on a phone layout (below 672px, or a phone held sideways), each row becomes a card instead of a squeezed table row. Off a phone the table renders exactly as without the prop.

  • The column marked primary is the card's title. Without one, the first column that is neither phoneHidden nor phoneMeta is.
  • Columns marked phoneMeta share one muted line under the title: a key, an owner, a date.
  • Every other column is a label and value pair, labelled with its header.
  • Columns marked phoneHidden are left out of the card.
  • Column widths are ignored, because there are no columns any more.
  • Sortable headers stay, as a strip of sort chips above the cards that cycle the same way the headers do. The select-all box stays beside them. With neither, or with no rows, the header is not shown, and the empty state is compact.
  • Clickable rows stay clickable, and the row actions sit at the end of the title line.
vue
<NbDataTable
  :columns="[
    { key: 'title', header: 'Title', primary: true, sortable: true },
    { key: 'key', header: 'Key', phoneMeta: true },
    { key: 'owner', header: 'Owner', phoneMeta: true },
    { key: 'status', header: 'Status' },
    { key: 'type', header: 'Type', phoneHidden: true },
  ]"
  :rows="rows"
  row-key="id"
  stack-on-phone
/>

Clickable rows ​

Listen for row-click and every row becomes clickable: the pointer cursor, and a place in the tab order. A row is reached with Tab and activated with Enter or Space, which emit the same row-click a click does, with the same row and index. A keyboard focus ring is drawn around the row in the library's focus colour, and a mouse click draws none. Clicks and keys on the selection control and the #row-actions cell stay theirs and do not activate the row.

This works the same with stackOnPhone, where each card is the focusable row. A table that does not listen for row-click has no tab stops on its rows and renders exactly as before.

vue
<template>
  <NbDataTable
    :columns="columns"
    :rows="rows"
    row-key="id"
    @row-click="(row) => open(row.id)"
  />
</template>

Each clickable row is its own tab stop, in reading order, rather than one tab stop with the arrow keys moving between rows. That keeps the table a plain table, and it is how a list of links behaves. For a long list, pair it with NbPagination so the number of stops stays small.

Expandable rows ​

Give the table a #row-detail slot and each row gets a toggle in a leading column. An open row shows the slot as a full-width region directly under it, spanning every column. Which rows are open is controlled, like selection: bind the open row keys with v-model:expanded. The toggle emits the next keys and the table shows what you pass back, so you decide whether several rows can be open at once, or only one.

The toggle is the only thing that opens a row. A row click still emits row-click, and a click on the toggle does not, so a row can be both clickable and expandable. With stackOnPhone, the toggle leads the card's title line and the detail opens inside the card, under its fields. A table without the slot has no toggle column and renders exactly as before.

vue
<template>
  <NbDataTable
    :columns="columns"
    :rows="rows"
    row-key="id"
    v-model:expanded="expanded"
  >
    <template #row-detail="{ row, rowIndex }">
      <MemberDetail :member="row" />
    </template>
  </NbDataTable>
</template>

<script setup lang="ts">
import { ref } from 'vue'

// Row keys, as `rowKey` gives them. Start with a row open by listing its key.
const expanded = ref<(string | number)[]>([2])
</script>

Only one row open at a time is a matter of what you pass back:

vue
<NbDataTable
  :columns="columns"
  :rows="rows"
  row-key="id"
  :expanded="expanded"
  @update:expanded="(keys) => (expanded = keys.slice(-1))"
>
  <template #row-detail="{ row }">
    <MemberDetail :member="row" />
  </template>
</NbDataTable>

Props ​

PropTypeDefaultDescription
columnsIDataTableColumn<T>[]requiredColumn definitions, left to right
rowsT[]requiredRow data (order is respected as-is)
rowKeykeyof T | (row: T) => string | numberrequiredRow identity for selection, keys and reconciliation
size'xs' | 'sm' | 'md' | 'lg' | 'xl''lg'Row height: 24, 32, 40, 48 or 64px
sortStateIDataTableSortState | nullnullControlled sort state, reflected in aria-sort
selectable'none' | 'single' | 'multiple''none'Row selection mode
selected(string | number)[][]Controlled selected keys (v-model:selected)
loadingbooleanfalseRenders skeleton placeholder rows
skeletonRowsnumber5Number of skeleton rows while loading
errorstring | booleanundefinedError message shown in place of the body. true shows the default Could not load the data from the strings catalogue
emptyMessagestringundefinedMessage shown when there are no rows
stickyHeaderbooleantruePins the header while the body scrolls
zebrabooleanfalseAlternating row backgrounds
fillbooleanfalseFill the parent's height and scroll internally
titlestringundefinedToolbar title
descriptionstringundefinedToolbar sub-text
ariaLabelstringundefinedAccessible name for the <table>
stackOnPhonebooleanfalseOn a phone, render each row as a stacked card
expanded(string | number)[][]Open detail row keys (v-model:expanded), read with a #row-detail slot
rowActions(row: T) => IActionGroupItem[]Each row's actions, as small ghost icon buttons with tooltips. Past three, an overflow menu

Interfaces ​

typescript
interface IDataTableColumn<T = Record<string, unknown>> {
  key: string
  header: string
  width?: string | number // number → px
  align?: 'left' | 'center' | 'right'
  sortable?: boolean
  render?: (row: T, value: unknown, rowIndex: number) => VNodeChild
  cellClass?: string
  hidden?: boolean
  primary?: boolean // with stackOnPhone: the card's title on a phone
  phoneHidden?: boolean // with stackOnPhone: left out of the card on a phone
  phoneMeta?: boolean // with stackOnPhone: on the muted line under the title
}

type TSortDirection = 'asc' | 'desc' | 'none'

interface IDataTableSortState {
  key: string
  direction: TSortDirection
}

Events ​

EventPayloadDescription
sortIDataTableSortStateNext sort state after a sortable header is activated
update:selected(string | number)[]Selected keys changed (v-model:selected)
row-click(row: T, rowIndex: number)A body row was clicked, or activated with Enter or Space (not checkbox / action cells)
update:expanded(string | number)[]Open detail row keys after a toggle (v-model:expanded)

Slots ​

SlotScopeDescription
cell-<key>{ row, value, column, rowIndex }Custom cell for column <key>
header-<key>{ column }Custom header for column <key>
toolbar{ selectedCount }Replaces the default title / description block
search(none)Search field, takes the toolbar's spare width
toolbar-actions(none)Toolbar buttons, the primary one last
batch-actions{ selectedKeys, clear }Actions shown in the batch bar during selection
row-actions{ row, rowIndex, disabled }Trailing actions column, when rowActions is not set
row-detail{ row, rowIndex }Detail shown under an open row; adds the toggle column
loading(none)(Skeleton rows render automatically)
empty(none)Empty-state content
error{ error }Error-state content
footer(none)Footer region (e.g. NbPagination)