Tree table

Hierarchical rows in a data table: a file system, an org chart, a bill of materials. It is vig-table with one more input, rowChildren: your own row objects stay as they are, and every table feature (column templates, sorting, filters, paging, selection, saved state, CSV export, the context menu) works on the tree.

  • vig-table
  • vig-col
  • ng-template[vigTableCell]
Import
import { Table, TableColumn, TableCell } from '@vigdx/ui/table';

Basic

Pass the root rows as items and an accessor of their children as rowChildren , e.g. (f: FileRow) => f.children : no wrapper type, no string paths. An array ( [] ) or null marks a leaf. The toggle sits in the rowHeader column (else the first one), indented by level; [(expandedRows)] holds the open rows, matched by rowId , so give rows a stable id. Sorting orders siblings within their parent: the hierarchy stays.

Files
src
Folder 5 KB
main.ts
TypeScript 1 KB
package.json
JSON 3 KB
README.md
Markdown 6 KB

Checkboxes

selectionMode="multiple" cascades in a tree table: checking a row checks its descendants (also collapsed ones), and a parent shows checked, unchecked or mixed from them. selection keeps the shape it has in any table, an array of your rows, and lists every checked row: implied checks (a parent you set, children loaded under a checked row) are written back into it, so the boxes, selection and the export always agree. rowSelectable locks rows: they show a disabled checkbox with their own state, the cascade passes through them, and their parent ignores them. [cascade]="false" makes every checkbox independent; single selects one row with a radio or a row click.

Files to publish
Name Kind
src
Folder
main.ts
TypeScript
docs
Folder
guide.md
Markdown
legacy.md
Markdown
package.json
JSON
README.md
Markdown

0 rows checked; legacy.md is locked.

Lazy loading

Rows whose rowChildren is undefined load their children with loadChildren(row, signal) on first expand, in the browser only (the server renders them busy, so hydration matches); [] or null marks a leaf. The row is aria-busy meanwhile, collapsing it aborts signal (pass it on to fetch ), and the answer of a cancelled or replaced loader is ignored. A rejected promise adds a row with a Retry button and is announced. Loaded children are kept per rowId across new items (also through an empty list while you refetch) and dropped for rows that leave the data; call reloadChildren(row?) when the server's data changed.

Remote folders
Name Items
notes.txt
0

Filtering and paging

Column filters and the global search look at every loaded row, at any level: a match shows with its ancestors, which open without being written to expandedRows (closing one while filtered is remembered until the filter changes), and its descendants stay reachable. The status announces how many rows match. The paginator pages the root rows, so a page can show more lines than rows when roots are expanded. exportCsv() exports every filtered row depth first, expanded or not.

Files

Virtual scrolling

virtualScroll renders only the rows in view: here 10,000 expanded rows. The window follows the rows on screen (expanded rows and their descendants), so expanding, collapsing, lazy loading, filtering and the cascading selection work as without it. The keys move by row index: End or Ctrl+End scrolls the last row into the window before it takes focus, and PageUp and PageDown move by a screen of the scroll area (a tree table that does not scroll itself leaves them to the page). The tab stop row and the focused row stay rendered wherever the view goes, and keys pressed while a row is on its way count from that row. Rows share one measured height and the columns keep their widths ( table-layout: fixed ), as in a flat virtual table.

Repository
Kind
folder-0
Folder2401 KB
file-0.ts
TypeScript0 KB
file-1.ts
TypeScript1 KB
file-2.ts
TypeScript2 KB
file-3.ts
TypeScript3 KB
file-4.ts
TypeScript4 KB
file-5.ts
TypeScript5 KB
file-6.ts
TypeScript6 KB
file-7.ts
TypeScript7 KB
file-8.ts
TypeScript8 KB
file-9.ts
TypeScript9 KB
file-10.ts
TypeScript10 KB
file-11.ts
TypeScript11 KB
file-12.ts
TypeScript12 KB
file-13.ts
TypeScript13 KB
file-14.ts
TypeScript14 KB
file-15.ts
TypeScript15 KB
file-16.ts
TypeScript16 KB
file-17.ts
TypeScript17 KB
file-18.ts
TypeScript18 KB
file-19.ts
TypeScript19 KB
file-20.ts
TypeScript20 KB
file-21.ts
TypeScript21 KB
file-22.ts
TypeScript22 KB
file-23.ts
TypeScript23 KB
file-24.ts
TypeScript24 KB
file-25.ts
TypeScript25 KB
file-26.ts
TypeScript26 KB
file-27.ts
TypeScript27 KB
file-28.ts
TypeScript28 KB
file-29.ts
TypeScript29 KB
file-30.ts
TypeScript30 KB
file-31.ts
TypeScript31 KB
file-32.ts
TypeScript32 KB
file-33.ts
TypeScript33 KB
file-34.ts
TypeScript34 KB
file-35.ts
TypeScript35 KB
file-36.ts
TypeScript36 KB
file-37.ts
TypeScript37 KB
file-38.ts
TypeScript38 KB

With the other table features

  • Column templates, sticky header, density, gridlines and stripes work as in any table; the toggle column wraps its cell template after the toggle.
  • Saved state (state) keeps the expanded rows by rowId, at any level: rows below a lazy level open once their parent loaded.
  • Context menu: a [vigContextMenu] on the table hands run the typed row it opened on, nested rows included.
  • Server-side tables (lazy): the server sorts, filters and pages the root rows; children load with loadChildren in the order given.
  • Cell editing: editable columns work at every level. Move to a cell with the arrow keys, then Enter, F2 or typing edits it; cellEdited hands you the nested row to replace in your data.
  • Not with tree rows: vigTableRowExpansion templates, groupBy and reorderableRows are ignored (with a dev-mode warning), since rows expand into their children.

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="table"][data-part="toolbar"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Scope: [data-scope="table"]

Table styling hooks
Part Element data-state
toolbar Row above the table: search and column toggle. —
search The built-in global search field. —
filter-indicator Notice of active filters on hidden columns. —
frame The bordered frame around the table. —
loading The loading overlay. —
scroll The scroll region. —
table The native <table> . —
head The <thead> . —
header-cell A column header <th> ( aria-sort ; data-frozen="start|end" when frozen, like every frozen cell). —
resize-handle The resize handle at the end of a resizable header ( role="separator" , resizableColumns ). dragging
sort The sort button of a sortable header. —
sort-priority The priority number of a column in a multi-sort. —
sort-priority-label The visually hidden text that reads the priority out. —
add-to-sort The control that adds a column to a multi-sort. —
filter-row The row of filter editors ( filterDisplay="row" ). —
filter-trigger A column filter menu button ( filterDisplay="menu" ). —
filter-panel The filter menu form, in a popover panel in the overlay container. —
clear-selection The button that clears a single selection. —
body The <tbody> . —
spacer A virtual table ( virtualScroll ): the aria-hidden row standing in for the rows above or below the rendered ones. —
group-header A group header row ( groupBy ). —
row A data row. selected
row-handle The move handle of a row ( reorderableRows ): drag it, Alt+ArrowUp/ArrowDown on it, or click it for its move menu. —
select The selection checkbox or radio of a row. —
select-all The header checkbox that selects every row of the page (multiple selection). —
expand The expand button of a row. —
cell A data cell, <td> or row-header <th> ( data-frozen="start|end" when frozen). editing
editor The default editor of a cell being edited (an editable column). —
editor-error The validation error under a cell editor ( aria-describedby of the editor). —
expansion The detail row of an expanded row. —
toggle The expand button of a tree row ( rowChildren ; aria-expanded , no Tab stop of its own). open, closed
children-loading The busy ring in place of the chevron while a row's children load. —
children-error The row under a tree row whose children failed to load. —
retry The retry button of that row. —
empty The empty-message row. —
paginator A vig-paginator (top and bottom). —

Accessibility

  • Follows the WAI-ARIA APG treegrid pattern: the table takes role="treegrid", named by its caption, and its rows aria-level, aria-setsize, aria-posinset (counting every root under a paginator) and, on parents, aria-expanded. With a selection, rows carry aria-selected and the grid is aria-multiselectable in multiple mode; the native checkboxes show mixed parents as indeterminate. With a rowHeader column, a row is named by its row-header cell.
  • The rows are one Tab stop (a roving tab index). ArrowDown and ArrowUp move between rows, ArrowRight opens a row or enters its first cell, ArrowLeft closes it or goes to its parent (both mirrored in right-to-left content), Home and End (also with Ctrl) jump to the first and last row, PageUp and PageDown move by a screen of rows, Enter is a row click (rowClick, and the selection in single mode) and Space selects (or, without selection, opens and closes). In a cell, the arrows move between cells, ArrowLeft from the first cell returns to the row, Home and End go to the row's first and last cell and Ctrl+Home and Ctrl+End to the column's first and last row. Enter or Space on the selection cell checks the row, and on an error row retries. The table is one Tab stop: its own controls in the rows (checkboxes, radios, the toggle, Retry) take no Tab stop of their own. Controls of your cell templates keep theirs; Enter or F2 on their cell moves focus into the first one, and Escape back to the cell, where the arrow keys move on (APG grid pattern). Alt and Cmd arrow combinations are left to the browser.
  • When the row with focus leaves the screen (its parent collapses, a filter changes, the data drops it), focus moves to its nearest ancestor on screen, else to the next row that stayed, never to the page.
  • With virtualScroll the treegrid carries aria-rowcount and every rendered row aria-rowindex; the keys work by index, so a row outside the rendered window scrolls in and then takes focus. The tab stop row and the focused row stay rendered at their own place while the view moves, so Tab always reaches the grid and focus never falls back to the page.
  • The toggle is a button named "Expand row" or "Collapse row" with the row's name (expandRowAriaLabel, collapseRowAriaLabel) and aria-expanded, so touch screen readers and voice control can open rows, but no Tab stop: the arrow keys do that for keyboard users. Its hit area is 24px, and on coarse pointers tree rows are at least 44px tall to fit a 44px one. Its chevron turns by CSS alone, so it follows a plain dir="rtl". A focused row draws an inset ring through its cells (an outline on a table row is not painted by every engine), focused cells an outline; in forced-colors mode every cell of the focused row outlines itself in Highlight.
  • A row whose children load is aria-busy and described as loading; a failed load is announced through the table's status region and adds a row that retries with Enter, Space or its Retry button.

API

Table

vig-table component

Data table for the backoffice list screens: client-side or lazy (server-side) sorting — by one column or several (sortMode="multiple") — column filters (columns with a filter, as a filter row or filter menus) and a global filter, pagination, checkbox or radio selection (a row click selects too), group subheaders, expandable rows, column visibility, CSV export, persisted state (state), loading and empty states. With rowChildren (or loadChildren) it becomes a tree table: the items are the root rows and the table an APG treegrid. virtualScroll renders only the rows in view, for tens of thousands of rows. Columns can be resized (resizableColumns), reordered (reorderableColumns) and frozen (vig-col frozen), also in a virtual table. Cells of editable columns are edited in place (cellEdited), and reorderableRows lets users move rows (rowReordered); the table never changes your items itself.

resize-handle dragging

Table props
Name Type Default Description
captionstring | undefinedundefined

Accessible table name, rendered as a visually hidden caption.

cascadebooleantrue

Tree table with selectionMode="multiple": checking a row checks its selectable descendants, and a parent shows checked, unchecked or mixed from them; selection lists every checked row, implied ones included (a parent set from outside, children loaded under a checked row are written back into it). Rows that rowSelectable rejects keep their own state and pass the cascade through. Off, every checkbox stands alone.

clearSelectionAriaLabelstring | undefinedundefined

Name of the single-selection column's clear button (i18n).

collapseRowAriaLabelstring | undefinedundefined
—
columnResizeModeTableColumnResizeMode'fit'

fit (default) keeps the table width: the next column gives or takes the difference. expand changes the table width, which then scrolls.

columnVisibility model Readonly<Record<string, boolean>>—

Visibility per column field, over each column's hidden.

emptyMessagestring | undefinedundefined
—
expandedRows model T[][]

Expanded rows of a table with a vigTableRowExpansion template, or the expanded parent rows of a tree table (rowChildren); identity via rowId.

expandRowAriaLabelstring | undefinedundefined
—
filterDisplayTableFilterDisplay'row'

row: a filter row under the header; menu: a filter button per header opening a menu.

filters model TableFilters—

Column filters by column field; written by the filter UI, settable from outside.

first model number0
—
globalFilter model string''

Text searched (contains) in every visible column, or in globalFilterFields.

globalFilterFieldsreadonly string[] | undefinedundefined

Column fields the global filter searches; every visible column with a field by default.

gridlinesbooleanfalse

Lines between columns as well as rows.

groupBystring | undefinedundefined

Inserts a subheader row whenever this property's value changes.

itemsreadonly T[][]
—
labelsPartial<TableLabels>—

Texts of the filter UI, multi-sort, toolbar and result status (i18n); locale defaults.

lazybooleanfalse

Rows are already paged/sorted by the server; state changes emit lazyLoad.

loadChildrenTableChildrenLoader<T> | undefinedundefined

Fetches the children of rows whose rowChildren is undefined on their first expand (makes the table a tree table on its own too); see TableChildrenLoader. Collapsing a loading row, or another loader, cancels the request; a failed load shows a retry row.

loadingbooleanfalse
—
loadingAriaLabelstring | undefinedundefined
—
paginatorbooleanfalse

Renders the embedded paginator and (non-lazy) slices the rows.

paginatorLabelsPaginatorLabels—
—
paginatorOptionsTablePaginatorOptions—

Paginator placement (position) and its jump-to-page field.

paginatorReportPositionPaginatorReportPosition'start'
—
paginatorSizePaginatorSize'sm'
—
reorderableColumnsbooleanfalse

Lets users reorder the columns with a field: drag a header (a long press on touch screens), or use the move buttons of the column menu, which then shows by default (toolbar.columns). The order is kept with state.

reorderableRowsbooleanfalse

Lets users move rows: drag a row by its handle (a long press on touch screens), press Alt+ArrowUp/ArrowDown (Alt+Home/End) on the handle or a cell, or pick a move from the handle's menu. Moves are announced and reported as rowReordered; set items to its items. Rows move in the order of items among the rows passing the filters, so moving is off while the table is sorted (or loading). A virtual table moves rows by keyboard and menu only; tree tables do not move rows.

resizableColumnsbooleanfalse

Adds a resize handle to the header of every column with a field (vig-col resizable opts single columns in or out): drag it, or focus it and use the arrow keys. Widths are kept with state.

rowChildrenTableChildrenAccessor<T> | undefinedundefined

Makes the table a tree table: the children of a row, e.g. (f: FileRow) => f.children. items are the root rows; your row objects stay as they are. [] or null marks a leaf, undefined a row whose children loadChildren fetches (a leaf without a loader).

The table then is an APG treegrid: a toggle in the row-header column (else the first column) expands rows (expandedRows), rows are one Tab stop moved by the arrow keys, sorting orders siblings within their parent, filters keep matching rows with their ancestors (shown expanded) and descendants, and the paginator pages the root rows. Row expansion templates and groupBy do not apply to tree tables.

rowExpandable((row: T) => boolean) | undefinedundefined

Which rows get an expansion toggle; every row when unset.

rowHoverbooleanfalse

Pointer feedback (hover fill + cursor) for rowClick-driven tables.

rowId((row: T) => unknown) | undefinedundefined

Row identity for selection and tracking, e.g. (u) => u.id.

rows model number10
—
rowSelectable((row: T) => boolean) | undefinedundefined

Which rows can be selected; every row when unset. The others show a disabled checkbox or radio with their own state, and a row click or the header checkbox leaves them as they are.

rowsPerPageOptionsreadonly number[][]
—
scrollHeightstring | undefinedundefined

Max height of the scrolling body area, any CSS length, e.g. 24rem or 60vh.

scrollRegionAriaLabelstring | undefinedundefined

Name of the scroll region when there is no caption.

selectAllAriaLabelstring | undefinedundefined
—
selection model T[][]

Selected rows; holds at most one entry in single mode.

selectionMode"none" | "single" | "multiple"'none'

single adds a radio column and multiple a checkbox column, named by the row header (rowHeader) or selectRowAriaLabel: native controls expose the selection to assistive tech and keyboards, which aria-selected on a plain table row does not. A row click also toggles the selection; in single mode the column header offers a clear button (clearSelectionAriaLabel). The controls belong to no form (form=""), so they are never submitted with, nor submit, a surrounding form.

selectRowAriaLabelstring | undefinedundefined
—
sizeTableSize'md'

Row density: vertical cell padding of the body rows.

sort model TableSort | nullnull

The sorted column; in multiple mode the one with the highest priority.

sortAscendingAnnouncementstring | undefinedundefined

Status announced after an ascending sort; {0} is the column header.

sortDescendingAnnouncementstring | undefinedundefined

Status announced after a descending sort; {0} is the column header.

sortIndicatorTableSortIndicator'always'

always marks every sortable header with a faint sort glyph; active shows only the sorted column's arrow and reveals the glyph of the others on hover or keyboard focus.

sortMode"single" | "multiple"'single'

multiple sorts by several columns: Shift+click (or Shift+Enter, Ctrl/Cmd+click) on a header adds it after the others, headers show each column's priority, and a third press removes a column's sort. A plain click sorts by that column alone.

sorts model TableSort[][]

Every sorted column in priority order: the source of truth in sortMode="multiple", where sort mirrors its first entry. Writing sort from outside in multiple mode sorts by that column alone.

stateTableStateOptions | undefinedundefined

Keeps sort, filters, page, page size, column visibility and expanded rows across visits: a storage key (localStorage), or { key, storage }. Restored in the browser right after the first render — never on the server, so hydration matches — and read once.

stickyHeaderbooleanfalse

Keeps the header row in view while the body scrolls (set scrollHeight too).

stripedbooleanfalse

Alternating row fills.

toolbarTableToolbar—

Built-in controls above the table: { search: true, columns: true }.

totalRecordsnumber | undefinedundefined

Total row count on the server (lazy mode).

virtualScrollTableVirtualScrollfalse

Renders only the body rows in view (and a few around them), for large flat or tree tables: true, or 'auto', which windows the rows from TABLE_VIRTUAL_THRESHOLD rows on. Either value gives the table its virtual layout at any row count, so crossing the threshold changes no layout: the body scrolls within scrollHeight, else the --vig-table-height token (24rem); the header is sticky; columns keep their widths while scrolling (table-layout: fixed: give columns a width, the others share the rest, at least --vig-table-column-min-width each, and the table scrolls sideways below that); cells stay on one line, ending in an ellipsis, since every row has one measured height (the full text stays in the DOM for screen readers, and plain cells show it as a title). The focused row stays rendered wherever the view goes. With the paginator it renders the page's rows. Does not apply to tables with a vigTableRowExpansion template (a dev-mode warning says so).

TableColumn

vig-col component

Declares one table column. Renders nothing itself — vig-table reads the inputs and the optional cell template:

Example :
<vig-col field="name" header="Name" [sortable]="true" />
<vig-col header="Actions">
  <ng-template vigTableCell let-row let-i="rowIndex">…</ng-template>
</vig-col>
TableColumn props
Name Type Default Description
align"start" | "center" | "end" | "left" | "right"'left'

Text alignment of the column's cells and header. start/end follow the text direction. left/right are deprecated aliases of them: they always aligned logically too (right is the left edge under RTL).

editablebooleanfalse

Lets users edit the column's cells (needs a field, which cellEdited reports): Enter, F2, a double click or typing on a cell opens the default text input (a number input for number values), or the column's vigTableCellEditor template. The table then is an APG grid.

editTypeTableCellEditType | undefinedundefined

The default editor of an editable column: number parses the text in the locale and commits number | null (also from an empty cell), text commits the text. Unset, it follows the cell's value: a number edits as a number, anything else (null too) as text.

fieldstring | undefinedundefined

Property read from the row for display and client-side sorting.

filterTableColumnFilterConfig | undefinedundefined

Makes the column filterable (needs a field): filter="text", or a typed config such as [filter]="{ type: 'select', options: statuses }". Rendered in the filter row or as a filter menu, per the table's filterDisplay.

frozenTableColumnFrozen | undefinedundefined

Keeps the column in view while the table scrolls horizontally, pinned to the inline start (with the selection and expansion columns) or end; logical, so it follows the text direction. Frozen columns render first (or last) and are reordered only among themselves. A bare frozen attribute means start.

headerstring''
—
hiddenbooleanfalse

Starts the column hidden; the column menu or columnVisibility can show it. Needs a field, the column's stable key (header text changes with the language): without one the column stays visible.

maxWidthnumber | undefinedundefined

Widest width a resize gives the column, in px; unlimited by default.

minWidthnumber | undefinedundefined

Narrowest width a resize leaves the column, in px; 48 by default.

resizableboolean | undefinedundefined

Gives the column a resize handle (true) or none (false) whatever the table's resizableColumns; unset, it follows the table. Needs a field, the key its width is kept by.

rowHeaderbooleanfalse

Renders this column's cells as row headers (<th scope="row">), e.g. a name column. They also complete the names of the row's selection checkbox and expand button ("Select row Alice"); the first such column wins.

sortablebooleanfalse
—
validateTableCellValidator | undefinedundefined

Checks an edited value before it is committed: an error message keeps the editor open showing it, null accepts the value.

valueTableValueAccessor | undefinedundefined

Typed accessor of the cell value, e.g. [value]="total" with total = (o: Order) => o.price * o.quantity. Used instead of row[field] for display (without a cell template), sorting, filtering, global search and CSV export; field then only names the column (its key in sort, filters and the persisted state).

widthstring | undefinedundefined

Any CSS width, e.g. '12rem' or '20%'.

Templates and directives

Templates and directives
Selector Export Description
[vigTableCell]TableCell

Marks an ng-template as a column's custom cell. The explicit marker keeps the query away from the TemplateRefs Angular creates for control-flow blocks (@if/@for) around the template. Like every directive, it only applies when the consuming component imports TableCell — without the import the template is silently ignored and cells render empty.

Are you sure?