Tree Table
A recipe: a Data Table whose rows open on their children — folders and files, tasks and subtasks — as a tree grid. No component of its own.
Usage
File Explorer
| Name | Size | Modified |
|---|---|---|
src | — | Apr 28 |
public | — | Mar 3 |
package.json | 2 KB | Apr 28 |
README.md | 6 KB | Mar 3 |
import { createColumnHelper, createExpandedRowModel, injectTable, rowExpandingFeature, tableFeatures,} from '@tanstack/angular-table';import { Component, ViewEncapsulation } from '@angular/core';import { ScFrame } from '@semantic-components/ui';import {How it is made
TanStack's expanding feature builds the tree: register rowExpandingFeature and an expanded row model, and give each row its children (getSubRows). The Data Table's parts show it.
scDataTableTreeGridis the table, in ascDataTableProviderthat holds TanStack's table: the rows below it are one tree.- In each row's first cell,
scDataTableTreeCellindents its content by the row's depth, andscDataTableExpandopens it — your chevron, pointing to the end, turned down when open; unseen on a row without children, so the names line up. scDataTableExpandAllopens every row, or closes them all.- Selection, sorting and filtering are the Data Table's, on the tree: selecting a row selects its children, sorting sorts each folder's rows among themselves, a filter keeps the folders of what it finds (
filterFromLeafRows).
import { ScDataTableProvider, ScDataTableContainer, ScDataTableTreeGrid, ScDataTableHeader, ScDataTableBody, ScDataTableRow, ScDataTableHeaderCell, ScDataTableCell, ScDataTableTreeCell, ScDataTableExpand, ScDataTableExpandAll,} from '@semantic-components/ui/data-table';<div scDataTableProvider [table]="table"> <button scDataTableExpandAll>…</button> <div scDataTableContainer> <table scDataTableTreeGrid aria-label="…"> <thead scDataTableHeader> <tr scDataTableRow><th scDataTableHeaderCell>…</th></tr> </thead> <tbody scDataTableBody> <tr scDataTableRow [row]="row"> <td scDataTableCell> <div scDataTableTreeCell [row]="row"> <button scDataTableExpand [row]="row">…</button> … </div> </td> </tr> </tbody> </table> </div></div>The parts' inputs: the Data Table's API reference.
Keyboard
The rows are one tab stop; the row is the control, not its buttons.
- ↓ and ↑: the next and the previous row; Home and End: the first and the last.
- → opens a row, or goes into it once open; ← closes it, or goes up to its parent — both mirrored right to left.
- Enter opens or closes a row.
- Space selects it, with the selection feature.
Accessibility
- A tree grid (WAI-ARIA): name it (
aria-label). Each row says its level, its place among its siblings and whether it is open — and, when rows can be selected, whether it is. - The expand buttons and the row checkboxes are out of the tab order, the buttons hidden from screen readers: the keys on the row do what they do. Still name them (a span with sr-only) for the pointer.
- A row's checkbox is half-ticked while only some of its children are selected.
Examples
Expand All
| Name | Size | Modified |
|---|---|---|
src | — | Apr 28 |
public | — | Mar 3 |
package.json | 2 KB | Apr 28 |
README.md | 6 KB | Mar 3 |
import { createColumnHelper, createExpandedRowModel, injectTable, rowExpandingFeature, tableFeatures,} from '@tanstack/angular-table';import { Component, ViewEncapsulation } from '@angular/core';import { ScFrame } from '@semantic-components/ui';import {Selection
| Name | Size | Modified | |
|---|---|---|---|
src | — | Apr 28 | |
public | — | Mar 3 | |
package.json | 2 KB | Apr 28 | |
README.md | 6 KB | Mar 3 |
0 selected
import { createColumnHelper, createExpandedRowModel, injectTable, rowExpandingFeature, rowSelectionFeature, tableFeatures,} from '@tanstack/angular-table';import { Component, ViewEncapsulation } from '@angular/core';import { ScCheckbox, ScField, ScFrame } from '@semantic-components/ui';Sorting
src | 9.4 kB |
app | 4.3 kB |
app.ts | 2.2 kB |
app-routes.ts | 0.8 kB |
app-config.ts | 1.3 kB |
main.ts | 0.6 kB |
styles.css | 4.5 kB |
public | 18.1 kB |
logo.svg | 3 kB |
favicon.ico | 15.1 kB |
package.json | 1.9 kB |
README.md | 6.2 kB |
import { type ExpandedState, createColumnHelper, createExpandedRowModel, createSortedRowModel, injectTable, rowExpandingFeature, rowSortingFeature, sortFn_alphanumeric, sortFn_basic,Filtering
| Name | Size | Modified |
|---|---|---|
src | — | Apr 28 |
public | — | Mar 3 |
package.json | 2 KB | Apr 28 |
README.md | 6 KB | Mar 3 |
import { columnFilteringFeature, createColumnHelper, createExpandedRowModel, createFilteredRowModel, globalFilteringFeature, injectTable, rowExpandingFeature, tableFeatures,} from '@tanstack/angular-table';RTL
| الاسم | الحجم | آخر تعديل |
|---|---|---|
src | — | ٢٨ أبريل |
public | — | ٣ مارس |
package.json | 2 KB | ٢٨ أبريل |
README.md | 6 KB | ٣ مارس |
import { createColumnHelper, createExpandedRowModel, injectTable, rowExpandingFeature, tableFeatures,} from '@tanstack/angular-table';import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScFrame } from '@semantic-components/ui';