Skip to main content

CnDataTable

Sortable data table with row selection, loading states, and schema-driven column generation. Supports dot notation for nested values (e.g., address.city).

Wraps: NcLoadingIcon, NcCheckboxRadioSwitch, CnCellRenderer

Try it

Loading CnDataTable playground…

CnDataTable showing sortable columns, checkboxes, and row action buttons

Anatomy

+--+------+----------↑---------+----------+----------+---------+----------------+
| | sel. | Column A ▲ | Column B | Column C | Column D| Actions header |
+--+------+--------------------+----------+----------+---------+----------------+
|☐ | 👤 | Alice van den Berg | Dept | email@.. | Active |⋮ |
|☐ | 👤 | Bob Jansen | Dept | email@.. | Pending |⋮ |
|☐ | 👤 | Carol Smit | Dept | email@.. | Active |⋮ |
+--+------+--------------------+----------+----------+---------+----------------+
↑ ↑ ↑ ↑ ↑
| avatar cell value badge row actions
checkbox renderer
RegionDescription
Select-all checkboxChecks/unchecks all rows on the current page
Column headersClickable to sort; cycles through ascending (▲), descending (▼), and no sort (indicator hidden)
Avatar / iconAuto-generated from the row's name field via CnCellRenderer
Cell valueType-aware rendering: email links, dates, booleans, status badges
Row actionsPer-row menu — rendered via the #row-actions slot
Actions headerSlot above actions row — rendered via the #actions-header slot (only renders when row actions exist)
Loading overlaySpinner centered over the table body while loading is true
Empty state"No items found" message (or #empty slot) when rows array is empty

Usage

<CnDataTable
:schema="schema"
:rows="objects"
:sort-key="sortKey"
:sort-order="sortOrder"
:selectable="true"
:selected-ids="selected"
@sort="onSort"
@select="onSelect"
@row-click="onRowClick">
<template #row-actions="{ row }">
<CnRowActions :actions="rowActions" :row="row" @action="onAction" />
</template>
</CnDataTable>

Props

PropTypeDefaultDescription
schemaObjectnullSchema object for auto-generating columns from its properties map
columnsArray[]Manual column definitions when not using schema: [{ key, label, sortable?, width?, class?, cellClass? }]
columnOverridesObject{}Per-column overrides applied on top of schema-generated columns; keyed by column key
excludeColumnsArray[]Column keys to hide when using schema auto-generation
includeColumnsArraynullWhitelist of column keys to show; all others hidden (takes precedence over excludeColumns)
rowsArray[]Array of row data objects to display
loadingBooleanfalseShows a loading spinner overlay while true
loadingTextString'Loading...'Accessible label for the loading spinner
sortKeyStringnullCurrently sorted column key; controls the ▲/▼ indicator. null means no column is actively sorted.
sortOrderString'asc'Current sort direction — 'asc', 'desc', or null (no sort)
selectableBooleanfalseEnables the checkbox column for multi-row selection
selectedIdsArray[]Array of currently selected row IDs (controlled)
rowKeyString'id'Property name used as the unique row identifier
emptyTextString'No items found'Message shown when rows is empty and no #empty slot is provided
rowClassFunctionnullCallback (row) => cssClass to add dynamic CSS classes to rows
cellClassFunctionnullCallback (row, col) => cssClass to add dynamic CSS classes to individual data cells
scrollableBooleanfalseEnables horizontal scrolling for wide tables

Events

EventPayloadDescription
sort{ key, order }Emitted when a sortable column header is clicked. Cycles through asc → desc → null. When the user clears the sort, both key and order are null.
selectids[]Emitted when row selection changes; payload is the full updated selection array
select-allisSelectAllEmitted when the select-all checkbox is toggled
row-clickrowEmitted when a data row is clicked (not the checkbox)
row-context-menu{ row, event }Emitted when a data row is right-clicked. The native contextmenu event is prevented. Used by CnIndexPage with the useContextMenu composable to show a context menu at the cursor position.

Slots

SlotScopeDescription
#column-{key}{ row, value }Override the cell renderer for a specific column key
#row-actions{ row }Content for the last (actions) cell of each row — typically CnRowActions
#actions-header-Content for the header above the actions cell — typically a button
#emptyCustom empty-state content shown when rows is empty

Reference (auto-generated)

The tables below are generated from the SFC source via vue-docgen-cli. They reflect what's actually in CnDataTable.vue and update automatically whenever the component changes.

Props

NameTypeRequiredDefaultDescription
columnsArray<{key: string, label: string, sortable: boolean, width: string, class: string, cellClass: string}>[]Column definitions (manual mode). Not required when schema is provided.
schemaobjectnullSchema object with properties field (schema-driven mode). When provided, columns are auto-generated from schema properties.
columnOverridesobject\{\}Per-column overrides when using schema mode: { key: { width, label, sortable, ... } }
excludeColumnsarray[]Column keys to exclude when using schema mode
includeColumnsarraynullColumn keys to include when using schema mode (whitelist)
rowsarray[]Row data array. Each row should have a unique identifier (see rowKey).
loadingbooleanfalseWhether data is loading (shows loading spinner)
sortKeystringnullCurrent sort column key
sortOrderstring'asc'Current sort order: 'asc', 'desc', or null (no sort)
selectablebooleanfalseWhether rows can be selected with checkboxes
selectedIdsarray[]Array of currently selected row IDs
rowKeystring'id'Property name used as unique row identifier
emptyTextstring() =&gt; t('nextcloud-vue', 'No items found')Text shown when there are no rows
rowClassfuncnullFunction returning CSS class(es) for a row: (row) => string|object
cellClassfuncnullFunction returning CSS class(es) for a data cell: (row, col) => string|object
scrollablebooleanfalseWhether to constrain table height and make it scrollable
loadingTextstring() =&gt; t('nextcloud-vue', 'Loading...')Text shown while loading

Events

NamePayloadDescription
row-click
row-context-menu
sortEmitted when a sortable column header is clicked.
selectEmitted when row selection changes. Payload: array of selected IDs.
select-allEmitted when select-all checkbox is toggled.

Slots

NameBindingsDescription
actions-header
empty
'column-' + col.keyname, row, value
row-actionsrow