Chapter 11 Data
Data table
Rows of records the reader scans and compares: orders, users, payments. A real table, named by its caption, so screen readers announce the row and column of every cell. Sorting is announced too.
import {
DataTableComponent,
TableCellDirective,Works with
Sorting, custom cells and pagination
Sort by customer, date or total. Status is a badge; totals line up on the last digit. The table only reports the sort: the page sorts and slices the rows, usually on the server.
| Order | Status | |||
|---|---|---|---|---|
| #1040 | Hatem Mohamed | 2026-11-18 | 85 EGP | |
| #1049 | Mohamed Ibrahim | 2026-11-18 | 418 EGP | |
| #1058 | Ibrahim Hatem | 2026-11-18 | 751 EGP | |
| #1041 | Mohamed Ibrahim | 2026-11-17 | 222 EGP | |
| #1050 | Ibrahim Hatem | 2026-11-17 | 555 EGP | |
| #1059 | Hatem Ibrahim | 2026-11-17 | 888 EGP | |
| #1042 | Ibrahim Hatem | 2026-11-16 | 359 EGP | |
| #1051 | Hatem Ibrahim | 2026-11-16 | 692 EGP |
columns: TableColumn<Order>[] = [
{ key: 'id', header: 'Order', value: (o) => '#' + o.id },
{ key: 'customer', header: 'Customer', sortable: true },
{ key: 'placed', header: 'Placed', sortable: true },
{ key: 'total', header: 'Total', sortable: true, align: 'end', value: (o) => o.total + ' EGP' },
{ key: 'status', header: 'Status' },
];
sort = signal<TableSort | null>({ key: 'placed', direction: 'descending' });
page = signal(1);
// Load or sort the rows for sort() and page(), usually on the server.
<ui-card>
<ui-data-table caption="Orders" [columns]="columns" [rows]="rows()" [(sort)]="sort" rowKey="id">
<ng-template uiCell="status" let-order>
<ui-badge [variant]="tone(order)">{{ order.status }}</ui-badge>
</ng-template>
</ui-data-table>
<ui-pagination [(page)]="page" [total]="total()" [pageSize]="8" />
</ui-card>Empty and loading
Say why the table is empty in words. While loading, the table is marked busy and screen readers hear the loading text once.
| Order | Status | |||
|---|---|---|---|---|
<ui-data-table
caption="Orders today"
[columns]="columns"
[rows]="rows()"
[loading]="loading()"
loadingLabel="Loading orders"
emptyMessage="No orders today yet."
/>In Arabic
| الطلب | العميل | الإجمالي |
|---|---|---|
| #1042 | حاتم محمد | ٣٤٠ جنيه |
| #1041 | محمد إبراهيم | ١٢٠ جنيه |
| #1040 | إبراهيم حاتم | ٨٥ جنيه |
<ui-data-table caption="الطلبات" [columns]="columns" [rows]="orders" rowKey="id" />
<ui-pagination [(page)]="page" [total]="23" [pageSize]="8" [labels]="labels" />
labels = {
nav: 'التنقل بين الصفحات',
previous: 'الصفحة السابقة',
next: 'الصفحة التالية',
page: (n: number) => `صفحة ${n}`,
summary: (first: number, last: number, total: number) => `${first}–${last} من ${total}`,
};Page navigation has its own page: Pagination.
When to use something else
| If you need | Use |
|---|---|
| A few label and value pairs | Property list |
| Events in time order | Timeline |
| Nested items such as folders | Tree |
Inputs
| Name | Type | Default | What it does |
|---|---|---|---|
caption | string | — | Required. Names the table; screen readers announce it. |
hideCaption | boolean | false | Keep the caption for screen readers only, when a heading above already names the table. |
columns | TableColumn<T>[] | — | Required. { key, header, sortable?, align?, value? } per column. |
rows | T[] | — | Required. The rows of the current page. |
sort | TableSort | null (model) | — | Bind [(sort)]: { key, direction }. Sort the rows yourself. |
rowKey | keyof T | (row) => unknown | — | What identifies a row, so rows keep their state across updates. |
loading / loadingLabel | boolean / string | false / 'Loading' | Marks the table busy and reads the label once. |
emptyMessage | string | 'No results' from labels | Shown when there are no rows; pass the translated text. |
ng-template uiCell="key" | directive | — | A custom cell for that column; let-row gives the row. |
Keyboard and screen readers
| Keys | What they do |
|---|---|
| Enter or Space | On a column heading, sort by it. |
- A real table named by its caption, so the row and column of every cell are read.
- The sorted column is marked, and the new order is announced.