# 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.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-table`, `vig-col`, `ng-template[vigTableCell]`
- Source: [libs/ui/src/lib/molecules/table/table.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/molecules/table/table.ts)

```typescript title="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.

```typescript title="tree-table-basic.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Table, TableCell, TableColumn } from '@vigdx/ui/table';

import { FILES, type FileRow } from './files';

@Component({
  selector: 'app-tree-table-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Table, TableColumn, TableCell],
  template: `
    <vig-table
      caption="Files"
      [items]="files"
      [rowId]="rowId"
      [rowChildren]="children"
      [(expandedRows)]="expanded"
    >
      <vig-col field="name" header="Name" [rowHeader]="true" [sortable]="true" />
      <vig-col field="kind" header="Kind" [sortable]="true" />
      <vig-col field="size" header="Size" [sortable]="true" align="end">
        <ng-template vigTableCell let-row>{{ row.size }} KB</ng-template>
      </vig-col>
    </vig-table>
  `,
})
export class TreeTableBasicDemo {
  protected readonly files = FILES;
  protected readonly expanded = signal<FileRow[]>([FILES[0]]);
  protected readonly rowId = (row: FileRow) => row.path;
  protected readonly children = (row: FileRow) => row.children;
}
```

## 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.

```typescript title="tree-table-checkbox.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Table, TableColumn } from '@vigdx/ui/table';

import { FILES, type FileRow } from './files';

@Component({
  selector: 'app-tree-table-checkbox',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Table, TableColumn],
  template: `
    <vig-table
      caption="Files to publish"
      [items]="files"
      [rowId]="rowId"
      [rowChildren]="children"
      [rowSelectable]="selectable"
      selectionMode="multiple"
      [(selection)]="selected"
      [expandedRows]="open"
    >
      <vig-col field="name" header="Name" [rowHeader]="true" />
      <vig-col field="kind" header="Kind" />
    </vig-table>
    <p class="text-sm text-muted-foreground" aria-live="polite">
      {{ selected().length }} rows checked; <code>legacy.md</code> is locked.
    </p>
  `,
})
export class TreeTableCheckboxDemo {
  protected readonly files = FILES;
  protected readonly open = [FILES[0], FILES[1]];
  protected readonly selected = signal<FileRow[]>([]);
  protected readonly rowId = (row: FileRow) => row.path;
  protected readonly children = (row: FileRow) => row.children;
  /** A locked row keeps its own state; checking `docs` passes it by. */
  protected readonly selectable = (row: FileRow) => row.path !== 'docs/legacy.md';
}
```

## 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.

```typescript title="tree-table-lazy.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Table, TableColumn, type TableChildrenLoader } from '@vigdx/ui/table';

interface Folder {
  path: string;
  name: string;
  items: number;
  /** `[]` for files; folders leave it out, so their children load on expand. */
  children?: Folder[];
}

@Component({
  selector: 'app-tree-table-lazy',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Table, TableColumn],
  template: `
    <vig-table
      caption="Remote folders"
      [items]="roots"
      [rowId]="rowId"
      [rowChildren]="children"
      [loadChildren]="load"
    >
      <vig-col field="name" header="Name" [rowHeader]="true" />
      <vig-col field="items" header="Items" align="end" />
    </vig-table>
  `,
})
export class TreeTableLazyDemo {
  protected readonly roots: Folder[] = [
    { path: '/projects', name: 'projects', items: 2 },
    { path: '/archive', name: 'archive (fails once)', items: 2 },
    { path: '/notes.txt', name: 'notes.txt', items: 0, children: [] },
  ];
  private failed = false;
  protected readonly rowId = (row: Folder) => row.path;
  protected readonly children = (row: Folder) => row.children;

  /** Stands in for `fetch(url, { signal })`; a collapse aborts it. */
  protected readonly load: TableChildrenLoader<Folder> = (row, signal) =>
    new Promise((resolve, reject) => {
      const timer = setTimeout(() => {
        if (row.path === '/archive' && !this.failed) {
          this.failed = true;
          reject(new Error('Network error'));
          return;
        }
        resolve([
          { path: `${row.path}/reports`, name: 'reports', items: 2 },
          { path: `${row.path}/summary.txt`, name: 'summary.txt', items: 0, children: [] },
        ]);
      }, 700);
      signal.addEventListener('abort', () => clearTimeout(timer));
    });
}
```

## 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.

```typescript title="tree-table-filter.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Table, TableColumn } from '@vigdx/ui/table';

import { FILES, type FileRow } from './files';

@Component({
  selector: 'app-tree-table-filter',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Table, TableColumn],
  template: `
    <vig-table
      caption="Files"
      [items]="files"
      [rowId]="rowId"
      [rowChildren]="children"
      [toolbar]="{ search: true }"
      [paginator]="true"
      [rows]="2"
    >
      <vig-col field="name" header="Name" [rowHeader]="true" [sortable]="true" filter="text" />
      <vig-col field="kind" header="Kind" [sortable]="true" />
      <vig-col field="size" header="Size (KB)" [sortable]="true" align="end" />
    </vig-table>
  `,
})
export class TreeTableFilterDemo {
  protected readonly files = FILES;
  protected readonly rowId = (row: FileRow) => row.path;
  protected readonly children = (row: FileRow) => row.children;
}
```

## 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.

```typescript title="tree-table-virtual.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Table, TableCell, TableColumn } from '@vigdx/ui/table';

import type { FileRow } from './files';

/** 100 folders of 99 files: 10,000 rows once expanded. */
function manyFiles(): FileRow[] {
  return Array.from({ length: 100 }, (_, f) => {
    const children = Array.from(
      { length: 99 },
      (_, i): FileRow => ({
        path: `folder-${f}/file-${i}.ts`,
        name: `file-${i}.ts`,
        size: (f * 99 + i) % 50,
        kind: 'TypeScript',
        children: [],
      }),
    );
    return {
      path: `folder-${f}`,
      name: `folder-${f}`,
      size: children.reduce((sum, child) => sum + child.size, 0),
      kind: 'Folder',
      children,
    };
  });
}

@Component({
  selector: 'app-tree-table-virtual',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Table, TableColumn, TableCell],
  template: `
    <vig-table
      caption="Repository"
      [items]="files"
      [rowId]="rowId"
      [rowChildren]="children"
      [(expandedRows)]="expanded"
      virtualScroll
    >
      <vig-col field="name" header="Name" [rowHeader]="true" [sortable]="true" />
      <vig-col field="kind" header="Kind" width="8rem" />
      <vig-col field="size" header="Size" width="6rem" [sortable]="true" align="end">
        <ng-template vigTableCell let-row>{{ row.size }} KB</ng-template>
      </vig-col>
    </vig-table>
  `,
})
export class TreeTableVirtualDemo {
  protected readonly files = manyFiles();
  protected readonly expanded = signal<FileRow[]>(this.files);
  protected readonly rowId = (row: FileRow) => row.path;
  protected readonly children = (row: FileRow) => row.children;
}
```

## 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](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="table"]`

| 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

Selector: `vig-table` · Kind: 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

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `caption` | `string \| undefined` | `undefined` | Accessible table name, rendered as a visually hidden caption. |
| `cascade` | `boolean` | `true` | 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. |
| `clearSelectionAriaLabel` | `string \| undefined` | `undefined` | Name of the single-selection column's clear button (i18n). |
| `collapseRowAriaLabel` | `string \| undefined` | `undefined` | — |
| `columnResizeMode` | `TableColumnResizeMode` | `'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`. |
| `emptyMessage` | `string \| undefined` | `undefined` | — |
| `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`. |
| `expandRowAriaLabel` | `string \| undefined` | `undefined` | — |
| `filterDisplay` | `TableFilterDisplay` | `'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) | `number` | `0` | — |
| `globalFilter` (model) | `string` | `''` | Text searched (`contains`) in every visible column, or in `globalFilterFields`. |
| `globalFilterFields` | `readonly string[] \| undefined` | `undefined` | Column fields the global filter searches; every visible column with a `field` by default. |
| `gridlines` | `boolean` | `false` | Lines between columns as well as rows. |
| `groupBy` | `string \| undefined` | `undefined` | Inserts a subheader row whenever this property's value changes. |
| `items` | `readonly T[]` | `[]` | — |
| `labels` | `Partial<TableLabels>` | — | Texts of the filter UI, multi-sort, toolbar and result status (i18n); locale defaults. |
| `lazy` | `boolean` | `false` | Rows are already paged/sorted by the server; state changes emit lazyLoad. |
| `loadChildren` | `TableChildrenLoader<T> \| undefined` | `undefined` | 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. |
| `loading` | `boolean` | `false` | — |
| `loadingAriaLabel` | `string \| undefined` | `undefined` | — |
| `paginator` | `boolean` | `false` | Renders the embedded paginator and (non-lazy) slices the rows. |
| `paginatorLabels` | `PaginatorLabels` | — | — |
| `paginatorOptions` | `TablePaginatorOptions` | — | Paginator placement (`position`) and its jump-to-page field. |
| `paginatorReportPosition` | `PaginatorReportPosition` | `'start'` | — |
| `paginatorSize` | `PaginatorSize` | `'sm'` | — |
| `reorderableColumns` | `boolean` | `false` | 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`. |
| `reorderableRows` | `boolean` | `false` | 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. |
| `resizableColumns` | `boolean` | `false` | 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`. |
| `rowChildren` | `TableChildrenAccessor<T> \| undefined` | `undefined` | 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) \| undefined` | `undefined` | Which rows get an expansion toggle; every row when unset. |
| `rowHover` | `boolean` | `false` | Pointer feedback (hover fill + cursor) for rowClick-driven tables. |
| `rowId` | `((row: T) => unknown) \| undefined` | `undefined` | Row identity for selection and tracking, e.g. `(u) => u.id`. |
| `rows` (model) | `number` | `10` | — |
| `rowSelectable` | `((row: T) => boolean) \| undefined` | `undefined` | 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. |
| `rowsPerPageOptions` | `readonly number[]` | `[]` | — |
| `scrollHeight` | `string \| undefined` | `undefined` | Max height of the scrolling body area, any CSS length, e.g. `24rem` or `60vh`. |
| `scrollRegionAriaLabel` | `string \| undefined` | `undefined` | Name of the scroll region when there is no `caption`. |
| `selectAllAriaLabel` | `string \| undefined` | `undefined` | — |
| `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. |
| `selectRowAriaLabel` | `string \| undefined` | `undefined` | — |
| `size` | `TableSize` | `'md'` | Row density: vertical cell padding of the body rows. |
| `sort` (model) | `TableSort \| null` | `null` | The sorted column; in `multiple` mode the one with the highest priority. |
| `sortAscendingAnnouncement` | `string \| undefined` | `undefined` | Status announced after an ascending sort; `{0}` is the column header. |
| `sortDescendingAnnouncement` | `string \| undefined` | `undefined` | Status announced after a descending sort; `{0}` is the column header. |
| `sortIndicator` | `TableSortIndicator` | `'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. |
| `state` | `TableStateOptions \| undefined` | `undefined` | 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. |
| `stickyHeader` | `boolean` | `false` | Keeps the header row in view while the body scrolls (set `scrollHeight` too). |
| `striped` | `boolean` | `false` | Alternating row fills. |
| `toolbar` | `TableToolbar` | — | Built-in controls above the table: `{ search: true, columns: true }`. |
| `totalRecords` | `number \| undefined` | `undefined` | Total row count on the server (lazy mode). |
| `virtualScroll` | `TableVirtualScroll` | `false` | 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). |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `cellEdited` | `TableCellEditEvent<T>` | A committed cell edit of an `editable` column. The table never changes your rows: update `items` immutably, e.g. `items.update((all) => all.map((r) => (r === row ? { ...r, [field]: value } : r)))`. |
| `columnReordered` | `TableColumnReorderEvent` | A column the user moved, by dragging its header or from the column menu. |
| `columnResized` | `TableColumnResizeEvent` | A column the user resized (pointer drag released, or a key press on its handle). |
| `columnVisibilityChange` | `Readonly<Record<string, boolean>>` | Visibility per column `field`, over each column's `hidden`. |
| `expandedRowsChange` | `T[]` | Expanded rows of a table with a `vigTableRowExpansion` template, or the expanded parent rows of a tree table (`rowChildren`); identity via `rowId`. |
| `filtersChange` | `TableFilters` | Column filters by column `field`; written by the filter UI, settable from outside. |
| `firstChange` | `number` | — |
| `globalFilterChange` | `string` | Text searched (`contains`) in every visible column, or in `globalFilterFields`. |
| `lazyLoad` | `TableLazyLoadEvent` | — |
| `rowClick` | `T` | Fired on any row click (all selection modes) — e.g. navigate to detail. Pointer shortcut only; give keyboard users an explicit control in a cell. |
| `rowReordered` | `TableRowReorderEvent<T>` | A row the user moved (`reorderableRows`): set `items` to the event's `items`. |
| `rowsChange` | `number` | — |
| `selectionChange` | `T[]` | Selected rows; holds at most one entry in single mode. |
| `sortChange` | `TableSort \| null` | The sorted column; in `multiple` mode the one with the highest priority. |
| `sortsChange` | `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. |

#### Methods

| Signature | Description |
| --- | --- |
| `clearFilters(): void` | Clears every column filter and the global filter, including values still being typed. |
| `exportCsv(options: TableCsvExportOptions = {}): string` | Exports the rows as CSV and, in the browser, downloads the file. By default: the visible columns with a `field` (read through `value`), every row passing the filters in the current sort order (all pages; the loaded rows in lazy mode), a UTF-8 BOM for Excel, and spreadsheet-formula neutralisation (see `CsvOptions.sanitize`). Returns the CSV text. |
| `isColumnVisible(column: TableColumn): boolean` | Whether the column shows: its `columnVisibility` override, else not `hidden`. Keyless columns always show. |
| `isExpanded(row: T): boolean` | — |
| `isSelected(row: T): boolean` | Whether the row is selected; with a cascading tree selection, whether it shows checked. |
| `reloadChildren(row?: T): void` | Forgets what `loadChildren` loaded for `row` and below it, or for every row without one, and cancels those loads: expanded rows load again, the others on their next expand. For data that changed on the server. |
| `scrollToIndex(index: number): void` | Scrolls the display row at `index` (the page's rows in display order; in a tree table the rows on screen, depth first) into view, at the top of a virtual table, which renders it first. Focus stays where it is. |
| `scrollToRow(row: T): boolean` | Scrolls `row` into view (see `scrollToIndex`). Returns `false` when it is not among the rows on screen: filtered out, on another page, or under a collapsed parent. |
| `setColumnVisible(column: TableColumn, visible: boolean): void` | Shows or hides a column (writes `columnVisibility`). Hiding a filtered column keeps its filter — hiding is a view change, not a request for other rows — and the toolbar then shows how many filters are active on hidden columns, with a "Clear filters" button; the change is announced. |
| `trackRow(row: T): unknown` | — |

### TableColumn

Selector: `vig-col` · Kind: component

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

**Example :**

```html
<vig-col field="name" header="Name" [sortable]="true" />
<vig-col header="Actions">
  <ng-template vigTableCell let-row let-i="rowIndex">…</ng-template>
</vig-col>
```

#### Inputs

| 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). |
| `editable` | `boolean` | `false` | 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. |
| `editType` | `TableCellEditType \| undefined` | `undefined` | 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. |
| `field` | `string \| undefined` | `undefined` | Property read from the row for display and client-side sorting. |
| `filter` | `TableColumnFilterConfig \| undefined` | `undefined` | 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`. |
| `frozen` | `TableColumnFrozen \| undefined` | `undefined` | 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`. |
| `header` | `string` | `''` | — |
| `hidden` | `boolean` | `false` | 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. |
| `maxWidth` | `number \| undefined` | `undefined` | Widest width a resize gives the column, in px; unlimited by default. |
| `minWidth` | `number \| undefined` | `undefined` | Narrowest width a resize leaves the column, in px; 48 by default. |
| `resizable` | `boolean \| undefined` | `undefined` | 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. |
| `rowHeader` | `boolean` | `false` | 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. |
| `sortable` | `boolean` | `false` | — |
| `validate` | `TableCellValidator \| undefined` | `undefined` | Checks an edited value before it is committed: an error message keeps the editor open showing it, `null` accepts the value. |
| `value` | `TableValueAccessor \| undefined` | `undefined` | 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). |
| `width` | `string \| undefined` | `undefined` | Any CSS width, e.g. '12rem' or '20%'. |

### 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 (/) 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. |
