@ithouse-bd/ngx-table 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -0
- package/DOCUMENTATION.md +711 -0
- package/LICENSE +21 -0
- package/README.md +304 -2
- package/THEMING.md +270 -0
- package/docs/images/table-dark.svg +136 -0
- package/docs/images/table-overview.svg +140 -0
- package/docs/images/table-selection.svg +164 -0
- package/fesm2022/ithouse-bd-ngx-table.mjs +1016 -0
- package/fesm2022/ithouse-bd-ngx-table.mjs.map +1 -0
- package/index.d.ts +516 -0
- package/index.d.ts.map +1 -0
- package/package.json +51 -3
package/DOCUMENTATION.md
ADDED
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
# @ithouse-bd/ngx-table — Documentation
|
|
2
|
+
|
|
3
|
+
Complete reference for `<ith-table>`: every input, output, template slot and recipe.
|
|
4
|
+
|
|
5
|
+
## Contents
|
|
6
|
+
|
|
7
|
+
- [Requirements](#requirements)
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Basic usage](#basic-usage)
|
|
10
|
+
- [Columns](#columns)
|
|
11
|
+
- [Sorting](#sorting)
|
|
12
|
+
- [Search and filters](#search-and-filters)
|
|
13
|
+
- [Pagination](#pagination)
|
|
14
|
+
- [Selection](#selection)
|
|
15
|
+
- [Row actions](#row-actions)
|
|
16
|
+
- [Custom templates](#custom-templates)
|
|
17
|
+
- [Loading and empty states](#loading-and-empty-states)
|
|
18
|
+
- [Server-side mode](#server-side-mode)
|
|
19
|
+
- [Programmatic API](#programmatic-api)
|
|
20
|
+
- [Accessibility](#accessibility)
|
|
21
|
+
- [Performance](#performance)
|
|
22
|
+
- [Troubleshooting](#troubleshooting)
|
|
23
|
+
- [Full input/output reference](#full-inputoutput-reference)
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+
|
|
27
|
+
## Requirements
|
|
28
|
+
|
|
29
|
+
- Angular **20 or newer** (standalone components, signal inputs, `model()`)
|
|
30
|
+
- No CSS framework required; the component ships its own scoped styles
|
|
31
|
+
|
|
32
|
+
Install:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @ithouse-bd/ngx-table
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The library is standalone-only; import the component and any template directives you use:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { TableComponent, TableCellDirective } from '@ithouse-bd/ngx-table';
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
> **Projected templates:** the `ithTableCell`, `ithTableHeader`, `ithTableFilter`,
|
|
45
|
+
> `ithTableRowActions`, `ithTableToolbar`, `ithTableFooter`, `ithTableEmpty` and
|
|
46
|
+
> `ithTableRowMenu` directives are used in *your* template, so import the ones you use into
|
|
47
|
+
> your component.
|
|
48
|
+
|
|
49
|
+
## Basic usage
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
interface Product {
|
|
53
|
+
id: number;
|
|
54
|
+
name: string;
|
|
55
|
+
category: string;
|
|
56
|
+
price: number;
|
|
57
|
+
stock: number;
|
|
58
|
+
active: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
readonly columns: TableColumn<Product>[] = [
|
|
62
|
+
{ key: 'name', header: 'Product', minWidth: '200px' },
|
|
63
|
+
{ key: 'category', header: 'Category' },
|
|
64
|
+
{ key: 'price', header: 'Price', align: 'right', formatter: (v) => `$${Number(v).toFixed(2)}` },
|
|
65
|
+
{ key: 'stock', header: 'Stock', align: 'center' },
|
|
66
|
+
{ key: 'active', header: 'Active', formatter: (v) => (v ? 'Yes' : 'No') },
|
|
67
|
+
];
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<ith-table
|
|
72
|
+
title="Products"
|
|
73
|
+
countSuffix="products"
|
|
74
|
+
[data]="products"
|
|
75
|
+
[columns]="columns"
|
|
76
|
+
[pageSize]="20">
|
|
77
|
+
</ith-table>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Defaults that matter:
|
|
81
|
+
|
|
82
|
+
| Option | Default |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| `mode` | `client` |
|
|
85
|
+
| `keyField` | `id` |
|
|
86
|
+
| `selectionMode` | `none` |
|
|
87
|
+
| `sortable` | `true` (per column) |
|
|
88
|
+
| `searchable` | `true` |
|
|
89
|
+
| `pageSize` | `10` |
|
|
90
|
+
| `pageSizeOptions` | `[10, 20, 50, 100]` |
|
|
91
|
+
| `hoverable` | `true` |
|
|
92
|
+
| `showToolbar` / `showFooter` | `true` |
|
|
93
|
+
| `showPagination` / `showPageSize` / `showFirstLast` | `true` |
|
|
94
|
+
|
|
95
|
+
## Columns
|
|
96
|
+
|
|
97
|
+
`TableColumn<T>` controls both data access and rendering:
|
|
98
|
+
|
|
99
|
+
| Field | Type | Description |
|
|
100
|
+
| --- | --- | --- |
|
|
101
|
+
| `key` | `string` | Unique id. Also the template name (`ithTableCell="key"`). |
|
|
102
|
+
| `header` | `string` | Header label; defaults to `key`. |
|
|
103
|
+
| `field` | `string` | Dot-path to the value, e.g. `customer.name`. Defaults to `key`. |
|
|
104
|
+
| `sortable` | `boolean` | Per-column override of the table-level `sortable`. |
|
|
105
|
+
| `searchable` | `boolean` | Include in global search (default `true`). |
|
|
106
|
+
| `filterable` | `boolean` | Show a control in the filter row (default `true`). |
|
|
107
|
+
| `filterType` | `'text' \| 'number' \| 'date' \| 'select'` | Control used by the filter (default `text`). |
|
|
108
|
+
| `filterOptions` | `{ label, value }[]` | Options of a `select` filter. |
|
|
109
|
+
| `filterPlaceholder` | `string` | Placeholder for this column's control. |
|
|
110
|
+
| `filterPredicate` | `(cellValue, filterValue, row) => boolean` | Custom matching rule (wins over `filterType`). |
|
|
111
|
+
| `align` | `'left' \| 'center' \| 'right'` | Header and cell alignment. |
|
|
112
|
+
| `width`, `minWidth` | `string` | CSS sizing, e.g. `'120px'`, `'20%'`. |
|
|
113
|
+
| `hidden` | `boolean` | Keep the config but hide the column. |
|
|
114
|
+
| `headerClass`, `cellClass` | `string` \| `(row, index) => string \| string[] \| object` | Extra classes. |
|
|
115
|
+
| `formatter` | `(value, row, index) => string \| number` | Display value; also used for search/filter matching. |
|
|
116
|
+
| `sortFn` | `(a: T, b: T) => number` | Custom ascending comparator. |
|
|
117
|
+
| `searchValue` | `(row: T) => string` | Custom text for the global search. |
|
|
118
|
+
| `filterValue` | `(row: T) => string` | Custom text for the column filter. |
|
|
119
|
+
| `tooltip` | `boolean` | Show the full cell text as a native tooltip (default `true`). |
|
|
120
|
+
| `sticky` | `'start' \| 'end'` | Keep the column pinned while scrolling horizontally (declare a `width`). |
|
|
121
|
+
|
|
122
|
+
Nested values work out of the box:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
{ key: 'name', field: 'customer.name', header: 'Customer' }
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Sorting
|
|
129
|
+
|
|
130
|
+
Clicking a sortable header cycles **ascending → descending → unsorted**. Bind `sort` for
|
|
131
|
+
two-way control or listen to `sortChange`:
|
|
132
|
+
|
|
133
|
+
```html
|
|
134
|
+
<ith-table
|
|
135
|
+
[data]="rows"
|
|
136
|
+
[columns]="columns"
|
|
137
|
+
[sort]="sort"
|
|
138
|
+
(sortChange)="sort = $event">
|
|
139
|
+
</ith-table>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
sort: TableSort | null = { key: 'price', direction: 'desc' };
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`TableSort` is `{ key: string; direction: 'asc' | 'desc' }`. Disable sorting table-wide with
|
|
147
|
+
`[sortable]="false"`, or per column with `{ sortable: false }`.
|
|
148
|
+
|
|
149
|
+
### Custom comparators
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
{
|
|
153
|
+
key: 'priority',
|
|
154
|
+
header: 'Priority',
|
|
155
|
+
sortFn: (a, b) => priorityWeight[a.priority] - priorityWeight[b.priority],
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Sorting compares raw values by default: numbers numerically, dates by time, strings with
|
|
160
|
+
`localeCompare` (`numeric: true`, case-insensitive).
|
|
161
|
+
|
|
162
|
+
## Search and filters
|
|
163
|
+
|
|
164
|
+
`searchable` (default `true`) renders a search input in the toolbar. It matches **any**
|
|
165
|
+
searchable column; searching is debounced by Angular change detection, not by a timer, so
|
|
166
|
+
bind `search` in server mode when you need throttling.
|
|
167
|
+
|
|
168
|
+
```html
|
|
169
|
+
<ith-table [data]="rows" [columns]="columns" [(search)]="term"></ith-table>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Per-column filters
|
|
173
|
+
|
|
174
|
+
```html
|
|
175
|
+
<ith-table [data]="rows" [columns]="columns" [showFilters]="true"></ith-table>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
A second header row appears with a control for **every column**. Each column decides what
|
|
179
|
+
it renders through `filterType`:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const columns: TableColumn<Order>[] = [
|
|
183
|
+
// text (default): keeps rows whose display text contains the input
|
|
184
|
+
{ key: 'customer', header: 'Customer' },
|
|
185
|
+
{ key: 'customer', field: 'customer.name', header: 'Customer', filterPlaceholder: 'Search…' },
|
|
186
|
+
|
|
187
|
+
// number: exact match on the numeric value
|
|
188
|
+
{ key: 'quantity', header: 'Qty', filterType: 'number' },
|
|
189
|
+
|
|
190
|
+
// date: exact match on yyyy-mm-dd
|
|
191
|
+
{ key: 'createdAt', field: 'createdAt', header: 'Created', filterType: 'date' },
|
|
192
|
+
|
|
193
|
+
// select: exact match, rendered as a dropdown
|
|
194
|
+
{
|
|
195
|
+
key: 'status',
|
|
196
|
+
header: 'Status',
|
|
197
|
+
filterType: 'select',
|
|
198
|
+
filterOptions: [
|
|
199
|
+
{ label: 'Paid', value: 'paid' },
|
|
200
|
+
{ label: 'Pending', value: 'pending' },
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
// custom matching: any rule you like
|
|
205
|
+
{
|
|
206
|
+
key: 'total',
|
|
207
|
+
header: 'Total',
|
|
208
|
+
filterType: 'number',
|
|
209
|
+
filterPredicate: (value, term) => Number(value) >= Number(term), // “total ≥ term”
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
// no filter control at all
|
|
213
|
+
{ key: 'notes', header: 'Notes', filterable: false },
|
|
214
|
+
];
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Select filters show an empty option labelled `[filterAllLabel]="'All'"`. Opt a column out
|
|
218
|
+
with `{ filterable: false }`, hide the whole row with `[showFilters]="false"` (the default),
|
|
219
|
+
or replace one control with your own template:
|
|
220
|
+
|
|
221
|
+
```html
|
|
222
|
+
<ng-template ithTableFilter="status" let-value let-setFn="setValue">
|
|
223
|
+
<select class="my-filter" [value]="value" (change)="setFn($any($event.target).value)">
|
|
224
|
+
<option value="">Everything</option>
|
|
225
|
+
<option value="paid">Paid</option>
|
|
226
|
+
<option value="pending">Pending</option>
|
|
227
|
+
</select>
|
|
228
|
+
</ng-template>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Context: `$implicit`/`value` (current filter text), `column`, `setValue(value: string)`.
|
|
232
|
+
Projected templates are styled by **your** component, so give them their own classes.
|
|
233
|
+
|
|
234
|
+
Filters are exposed as `filters` (`Record<columnKey, string>`), two-way bindable, and as the
|
|
235
|
+
`filterChange` output:
|
|
236
|
+
|
|
237
|
+
```html
|
|
238
|
+
<ith-table [(filters)]="filters" (filterChange)="load()"></ith-table>
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
In **client mode** search and filters reset the table to page 1 automatically. In **server
|
|
242
|
+
mode** nothing is filtered locally and the table never moves the page on its own: it passes
|
|
243
|
+
the whole `filterChange` record to you, and your handler should reset the page while it
|
|
244
|
+
fetches the filtered page back.
|
|
245
|
+
|
|
246
|
+
The empty state offers a “Clear search & filters” action.
|
|
247
|
+
|
|
248
|
+
Matching rules: `text` matches the formatted cell text, `number` compares numerically
|
|
249
|
+
(`12`, `12.0` and `012` all match 12), `date` compares the calendar date so an ISO string
|
|
250
|
+
such as `2026-10-05T23:00:00Z` is never shifted by a time zone, and `select` matches the
|
|
251
|
+
option value exactly.
|
|
252
|
+
|
|
253
|
+
## Pagination
|
|
254
|
+
|
|
255
|
+
The footer shows `Showing 1–10 of 13`, the `totalLabel` count, a numbered page window,
|
|
256
|
+
first/previous/next/last buttons and a rows-per-page selector.
|
|
257
|
+
|
|
258
|
+
```html
|
|
259
|
+
<ith-table
|
|
260
|
+
[data]="rows"
|
|
261
|
+
[columns]="columns"
|
|
262
|
+
[(page)]="page"
|
|
263
|
+
[(pageSize)]="pageSize"
|
|
264
|
+
[pageSizeOptions]="[5, 10, 25, 100]"
|
|
265
|
+
[maxPageButtons]="7"
|
|
266
|
+
(pageChange)="onPage($event)">
|
|
267
|
+
</ith-table>
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
`pageChange` emits the new page number, `pageSizeChange` the new page size. All three of
|
|
271
|
+
`page`, `pageSize` and `pageSizeOptions` can be bound; hide parts of the footer with
|
|
272
|
+
`[showPagination]="false"`, `[showPageSize]="false"` or `[showFirstLast]="false"`.
|
|
273
|
+
|
|
274
|
+
If data shrinks, the current page is clamped to the last available page automatically.
|
|
275
|
+
|
|
276
|
+
## Selection
|
|
277
|
+
|
|
278
|
+
```html
|
|
279
|
+
<ith-table
|
|
280
|
+
[data]="rows"
|
|
281
|
+
[columns]="columns"
|
|
282
|
+
selectionMode="multi"
|
|
283
|
+
[(selected)]="selected">
|
|
284
|
+
</ith-table>
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
| Input | Description |
|
|
288
|
+
| --- | --- |
|
|
289
|
+
| `selectionMode` | `'none'`, `'single'` or `'multi'` |
|
|
290
|
+
| `selectAllScope` | `'page'` (default) selects the visible page, `'all'` selects every filtered row |
|
|
291
|
+
| `selectOnRowClick` | Click anywhere on a row to toggle it (default `false`) |
|
|
292
|
+
| `keyField` | Row identity; selection survives sorting, filtering and paging by key |
|
|
293
|
+
| `selected` | Two-way bindable array of selected rows |
|
|
294
|
+
|
|
295
|
+
`selectedChange` emits the selected rows. Header checkbox reflects `allPageSelected()` and
|
|
296
|
+
shows an indeterminate state when only some rows of the page are selected.
|
|
297
|
+
|
|
298
|
+
Selection across pages is preserved by key. For server mode, keys are compared to the rows
|
|
299
|
+
currently in `selected`, so keep the objects you put there.
|
|
300
|
+
|
|
301
|
+
Public helpers: `toggleRow(row, checked)`, `toggleAll(checked)`, `selectRow(row)`,
|
|
302
|
+
`deselectRow(row)`, `clearSelection()`, `isSelected(row)`.
|
|
303
|
+
|
|
304
|
+
## Row actions
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
readonly actions: TableRowAction<Order>[] = [
|
|
308
|
+
{ id: 'view', label: 'View', icon: '👁' },
|
|
309
|
+
{ id: 'ship', label: 'Ship', disabled: (row) => row.status !== 'paid', hidden: (row) => row.cancelled },
|
|
310
|
+
{ id: 'cancel', label: 'Cancel', class: 'is-danger' },
|
|
311
|
+
];
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
```html
|
|
315
|
+
<ith-table
|
|
316
|
+
[data]="orders"
|
|
317
|
+
[columns]="columns"
|
|
318
|
+
[rowActions]="actions"
|
|
319
|
+
actionsHeader="Actions"
|
|
320
|
+
actionsWidth="180px"
|
|
321
|
+
(actionClick)="onAction($event)">
|
|
322
|
+
</ith-table>
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
onAction(event: TableActionEvent<Order>): void {
|
|
327
|
+
const { action, row, index } = event;
|
|
328
|
+
if (action.id === 'view') this.router.navigate(['/orders', row.id]);
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
The actions column is rendered only when `rowActions` is non-empty **or** a
|
|
333
|
+
`#ithTableRowActions` template exists. Buttons stop click propagation, so row clicks (and
|
|
334
|
+
`selectOnRowClick`) are not triggered.
|
|
335
|
+
|
|
336
|
+
## Custom templates
|
|
337
|
+
|
|
338
|
+
All templates are optional. Import the matching directives in your component.
|
|
339
|
+
|
|
340
|
+
### Cell — `ithTableCell="key"`
|
|
341
|
+
|
|
342
|
+
```html
|
|
343
|
+
<ng-template ithTableCell="status" let-row let-value="value" let-index="index">
|
|
344
|
+
<span class="badge" [class.bg-success]="value === 'active'">{{ value }}</span>
|
|
345
|
+
</ng-template>
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
Context: `$implicit`/`row`, `column`, `value`, `index`.
|
|
349
|
+
|
|
350
|
+
### Header — `ithTableHeader="key"`
|
|
351
|
+
|
|
352
|
+
```html
|
|
353
|
+
<ng-template ithTableHeader="price" let-column="column">
|
|
354
|
+
<span class="d-inline-flex align-items-center gap-1">
|
|
355
|
+
{{ column.header }} <small class="text-muted">USD</small>
|
|
356
|
+
</span>
|
|
357
|
+
</ng-template>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Context: `$implicit`/`column`.
|
|
361
|
+
|
|
362
|
+
### Filter control — `ithTableFilter="key"`
|
|
363
|
+
|
|
364
|
+
```html
|
|
365
|
+
<ng-template ithTableFilter="customer" let-value let-setFn="setValue" let-column="column">
|
|
366
|
+
<input class="search" [value]="value" (input)="setFn($any($event.target).value)" />
|
|
367
|
+
</ng-template>
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
Context: `$implicit`/`value`, `column`, `setValue`. Changing the value behaves exactly like
|
|
371
|
+
the built-in control (server mode emits `filterChange`, page resets to 1).
|
|
372
|
+
|
|
373
|
+
### Row actions — `ithTableRowActions`
|
|
374
|
+
|
|
375
|
+
```html
|
|
376
|
+
<ng-template ithTableRowActions let-row let-index="index">
|
|
377
|
+
<button type="button" class="btn btn-sm" (click)="edit(row)">Edit</button>
|
|
378
|
+
<button type="button" class="btn btn-sm btn-danger" (click)="remove(row, index)">Delete</button>
|
|
379
|
+
</ng-template>
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Context: `$implicit`/`row`, `index`.
|
|
383
|
+
|
|
384
|
+
### Toolbar — `ithTableToolbar`
|
|
385
|
+
|
|
386
|
+
Rendered next to the title and count badge:
|
|
387
|
+
|
|
388
|
+
```html
|
|
389
|
+
<ng-template ithTableToolbar let-total="total" let-selected="selected">
|
|
390
|
+
<button class="btn btn-sm btn-primary" (click)="exportRows()">
|
|
391
|
+
Export {{ total }}
|
|
392
|
+
</button>
|
|
393
|
+
@if (selected.length) {
|
|
394
|
+
<button class="btn btn-sm btn-outline-danger" (click)="bulkDelete()">
|
|
395
|
+
Delete {{ selected.length }}
|
|
396
|
+
</button>
|
|
397
|
+
}
|
|
398
|
+
</ng-template>
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Context: `rows` (current page), `total`, `selected`, `search`.
|
|
402
|
+
|
|
403
|
+
### Footer — `ithTableFooter`
|
|
404
|
+
|
|
405
|
+
Replaces the default summary **only**; pagination controls stay. Context adds `page`,
|
|
406
|
+
`pageSize`, `pageCount`:
|
|
407
|
+
|
|
408
|
+
```html
|
|
409
|
+
<ng-template ithTableFooter let-page="page" let-page-count="pageCount" let-total="total">
|
|
410
|
+
<span>Page {{ page }} of {{ pageCount }} — {{ total }} records</span>
|
|
411
|
+
</ng-template>
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
### Empty — `ithTableEmpty`
|
|
415
|
+
|
|
416
|
+
```html
|
|
417
|
+
<ng-template ithTableEmpty>
|
|
418
|
+
<div class="text-center py-4">
|
|
419
|
+
<p class="mb-2">Nothing here yet.</p>
|
|
420
|
+
<button class="btn btn-primary" (click)="create()">Create the first record</button>
|
|
421
|
+
</div>
|
|
422
|
+
</ng-template>
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
## Copy, context menu & presets
|
|
426
|
+
|
|
427
|
+
### Copy
|
|
428
|
+
|
|
429
|
+
```html
|
|
430
|
+
<ith-table [data]="rows" [columns]="columns" [copyable]="true"
|
|
431
|
+
(cellCopy)="onCopy($event)"></ith-table>
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
- A copy button appears on cell hover; `Ctrl`/`Cmd` + `C` copies the focused cell too.
|
|
435
|
+
- `(cellCopy)` emits `{ value, row, index, column }`; `column` is `null` when a full row was
|
|
436
|
+
copied with `copyRow(row, index)`.
|
|
437
|
+
|
|
438
|
+
### Right-click menu
|
|
439
|
+
|
|
440
|
+
```html
|
|
441
|
+
<ith-table [data]="rows" [columns]="columns">
|
|
442
|
+
<ng-template ithTableRowMenu let-row let-index="index">
|
|
443
|
+
<button type="button" (click)="open(row)">Open</button>
|
|
444
|
+
<button type="button" (click)="remove(row, index)">Delete</button>
|
|
445
|
+
</ng-template>
|
|
446
|
+
</ith-table>
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
- Right-click or `Shift+F10` / the context-menu key emits `rowContextMenu`
|
|
450
|
+
(`{ row, index, x, y, event }`) and renders the template in a fixed panel at the pointer.
|
|
451
|
+
- The panel closes on outside click or `Escape`; `closeRowMenu()` closes it from code.
|
|
452
|
+
- Without an `ithTableRowMenu` template the event is still emitted (for your own popover)
|
|
453
|
+
and the browser menu is left alone.
|
|
454
|
+
|
|
455
|
+
### Column visibility, density and presets
|
|
456
|
+
|
|
457
|
+
```html
|
|
458
|
+
<ith-table [data]="rows" [columns]="columns"
|
|
459
|
+
[showColumnPicker]="true"
|
|
460
|
+
[showDensityToggle]="true"
|
|
461
|
+
storageKey="students-table"
|
|
462
|
+
(columnsChange)="onColumns($event)"
|
|
463
|
+
(densityChange)="onDensity($event)"></ith-table>
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
- The "Columns" popover toggles visibility without touching the column config; at least one
|
|
467
|
+
column always stays visible.
|
|
468
|
+
- With `storageKey`, the hidden-column list and the comfortable/compact density are restored
|
|
469
|
+
from `localStorage` on the next visit. Call `resetColumns()` to clear the selection.
|
|
470
|
+
- `dense` still forces compact rows; the toggle only switches the runtime density.
|
|
471
|
+
|
|
472
|
+
### Sticky columns and tooltips
|
|
473
|
+
|
|
474
|
+
```typescript
|
|
475
|
+
columns: TableColumn<Row>[] = [
|
|
476
|
+
{ key: 'name', header: 'Name', width: '220px', sticky: 'start' },
|
|
477
|
+
{ key: 'email', header: 'Email' },
|
|
478
|
+
{ key: 'notes', header: 'Notes', tooltip: true },
|
|
479
|
+
];
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
- `sticky: 'start' | 'end'` pins that column; declare a pixel `width` so the next sticky
|
|
483
|
+
column can be offset.
|
|
484
|
+
- `[stickySelection]="true"` / `[stickyActions]="true"` pin the checkbox and actions columns.
|
|
485
|
+
- `tooltip: false` disables the native title for a column.
|
|
486
|
+
|
|
487
|
+
## Loading and empty states
|
|
488
|
+
|
|
489
|
+
```html
|
|
490
|
+
<ith-table
|
|
491
|
+
[data]="rows"
|
|
492
|
+
[columns]="columns"
|
|
493
|
+
[loading]="loading()"
|
|
494
|
+
loadingText="Fetching orders…"
|
|
495
|
+
emptyText="No orders for this period">
|
|
496
|
+
</ith-table>
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
- With no rows, a spinner and `loadingText` replace the empty state.
|
|
500
|
+
- With rows, a translucent overlay keeps the current rows visible while loading.
|
|
501
|
+
- `hasQuery()` in the empty state switches the message to “No records match your search.”
|
|
502
|
+
and offers a clear action.
|
|
503
|
+
|
|
504
|
+
## Server-side mode
|
|
505
|
+
|
|
506
|
+
```typescript
|
|
507
|
+
readonly pageRows = signal<Order[]>([]);
|
|
508
|
+
readonly total = signal(0);
|
|
509
|
+
readonly loading = signal(false);
|
|
510
|
+
readonly page = signal(1);
|
|
511
|
+
readonly pageSize = signal(10);
|
|
512
|
+
readonly sort = signal<TableSort | null>({ key: 'createdAt', direction: 'desc' });
|
|
513
|
+
readonly search = signal('');
|
|
514
|
+
|
|
515
|
+
constructor() {
|
|
516
|
+
effect(() => {
|
|
517
|
+
// Any query change triggers a reload; signals make this zoneless-safe.
|
|
518
|
+
void this.fetch(this.page(), this.pageSize(), this.sort(), this.search());
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
private async fetch(page: number, pageSize: number, sort: TableSort | null, search: string) {
|
|
523
|
+
this.loading.set(true);
|
|
524
|
+
const result = await this.api.orders({ page, pageSize, sort, search });
|
|
525
|
+
this.pageRows.set(result.items);
|
|
526
|
+
this.total.set(result.total);
|
|
527
|
+
this.loading.set(false);
|
|
528
|
+
}
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
```html
|
|
532
|
+
<ith-table
|
|
533
|
+
mode="server"
|
|
534
|
+
[data]="pageRows()"
|
|
535
|
+
[total]="total()"
|
|
536
|
+
[loading]="loading()"
|
|
537
|
+
[columns]="columns"
|
|
538
|
+
[page]="page()"
|
|
539
|
+
[pageSize]="pageSize()"
|
|
540
|
+
[sort]="sort()"
|
|
541
|
+
[search]="search()"
|
|
542
|
+
(pageChange)="page.set($event)"
|
|
543
|
+
(pageSizeChange)="pageSize.set($event); page.set(1)"
|
|
544
|
+
(sortChange)="sort.set($event)"
|
|
545
|
+
(searchChange)="search.set($event); page.set(1)">
|
|
546
|
+
</ith-table>
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
Notes:
|
|
550
|
+
|
|
551
|
+
- In server mode the table renders exactly `[data]`; it never slices or re-sorts.
|
|
552
|
+
- `[total]` drives the page count and the footer range. Fall back to `data.length` when it is `0`.
|
|
553
|
+
- The table owns the page in **client** mode only (query changes restart at page 1). In
|
|
554
|
+
server mode reset `page` yourself in the `searchChange` / `filterChange` /
|
|
555
|
+
`pageSizeChange` handlers — that keeps a query change to a single request.
|
|
556
|
+
- `selectAllScope="all"` can only select the rows you have loaded; for true “select all”
|
|
557
|
+
keep a server-side flag instead.
|
|
558
|
+
|
|
559
|
+
## Programmatic API
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
@ViewChild(TableComponent) table!: TableComponent<Order>;
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
| Method | Description |
|
|
566
|
+
| --- | --- |
|
|
567
|
+
| `goToPage(page)` | Clamp and navigate |
|
|
568
|
+
| `nextPage()` / `previousPage()` / `firstPage()` / `lastPage()` | Navigation helpers |
|
|
569
|
+
| `toggleSort(column)` | Cycle a column's sort state |
|
|
570
|
+
| `toggleRow(row, checked)` / `toggleAll(checked)` | Selection |
|
|
571
|
+
| `selectRow(row)` / `deselectRow(row)` / `clearSelection()` | Selection helpers |
|
|
572
|
+
| `isSelected(row)` / `rowKey(row)` | Selection inspection |
|
|
573
|
+
| `clearSearch()` / `clearFilters()` / `clearQuery()` | Reset search state |
|
|
574
|
+
|
|
575
|
+
Expose `sort`, `search`, `page`, `pageSize`, `selected` and `filters` publicly to reset
|
|
576
|
+
them from the parent.
|
|
577
|
+
|
|
578
|
+
## Accessibility
|
|
579
|
+
|
|
580
|
+
- Native `<table>`, `<thead>`/`<tbody>`, `<th scope="col">` markup.
|
|
581
|
+
- `aria-sort` on sortable headers (`ascending` / `descending` / `none`).
|
|
582
|
+
- Header and row checkboxes have explicit `aria-label`s; the header checkbox supports the
|
|
583
|
+
indeterminate state.
|
|
584
|
+
- Pagination is a `<nav aria-label="Pagination">` with labelled first/previous/next/last
|
|
585
|
+
buttons and `aria-current="page"` on the active page number.
|
|
586
|
+
- Sort headers and page buttons are real `<button>`s, so keyboard and screen readers work.
|
|
587
|
+
- Clickable rows (`rowClickable` / `selectOnRowClick`) are focusable and activate with
|
|
588
|
+
`Enter` or `Space`, exactly like a mouse click.
|
|
589
|
+
- Selectable rows expose `aria-selected`; the header checkbox reflects “all on page” and
|
|
590
|
+
the indeterminate state.
|
|
591
|
+
- `aria-busy` reflects `loading`, the loading/empty cell is `aria-live="polite"`, and
|
|
592
|
+
`aria-label` names the table (`ariaLabel` input).
|
|
593
|
+
- `prefers-reduced-motion` disables row, button and input transitions.
|
|
594
|
+
|
|
595
|
+
## Performance
|
|
596
|
+
|
|
597
|
+
- Set `keyField` to a real unique field so `@for` tracks rows by key.
|
|
598
|
+
- Use `mode="server"` for large datasets instead of paging thousands of rows in the browser.
|
|
599
|
+
- Provide `track`-friendly stable row objects; the table never mutates your array.
|
|
600
|
+
- Avoid heavy work inside `formatter` / `cellClass` callbacks; they run per rendered cell.
|
|
601
|
+
|
|
602
|
+
## Troubleshooting
|
|
603
|
+
|
|
604
|
+
**Template directives are ignored / “not a known property”**
|
|
605
|
+
Import `TableCellDirective` (and friends) into the component that declares the template.
|
|
606
|
+
|
|
607
|
+
**Styles don’t show up**
|
|
608
|
+
Component styles are scoped; do not set `encapsulation: ViewEncapsulation.None` on the
|
|
609
|
+
consumer and avoid `display: none` on the host. The table needs its host `display: block`.
|
|
610
|
+
|
|
611
|
+
**Angular budget warning for component styles**
|
|
612
|
+
The table stylesheet is ~15 kB uncompressed (~3 kB gzipped). If your Angular project uses
|
|
613
|
+
the default `anyComponentStyle` budget (8 kB), raise it:
|
|
614
|
+
|
|
615
|
+
```json
|
|
616
|
+
{
|
|
617
|
+
"type": "anyComponentStyle",
|
|
618
|
+
"maximumWarning": "16kb",
|
|
619
|
+
"maximumError": "20kb"
|
|
620
|
+
}
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
**Page resets unexpectedly**
|
|
624
|
+
In client mode changing `search`, `filters`, `sort` or `pageSize` returns to page 1 on
|
|
625
|
+
purpose. In server mode the table never resets the page — if it jumps, your own handler
|
|
626
|
+
(or a clamped `page` after the total shrank) is doing it.
|
|
627
|
+
|
|
628
|
+
**Selection is lost after refetch (server mode)**
|
|
629
|
+
Rows are compared by `keyField`; pass the same row objects (or at least the same keys) in
|
|
630
|
+
`[(selected)]`, and don’t rebuild selected objects with different ids.
|
|
631
|
+
|
|
632
|
+
## Full input/output reference
|
|
633
|
+
|
|
634
|
+
### Inputs
|
|
635
|
+
|
|
636
|
+
| Input | Type | Default |
|
|
637
|
+
| --- | --- | --- |
|
|
638
|
+
| `data` | `T[]` | `[]` |
|
|
639
|
+
| `columns` | `TableColumn<T>[]` | `[]` |
|
|
640
|
+
| `keyField` | `string` | `'id'` |
|
|
641
|
+
| `mode` | `'client' \| 'server'` | `'client'` |
|
|
642
|
+
| `total` | `number` | `0` |
|
|
643
|
+
| `title` | `string` | `''` |
|
|
644
|
+
| `countSuffix` | `string` | `'items'` |
|
|
645
|
+
| `totalLabel` | `string` | `'Total Found'` |
|
|
646
|
+
| `ariaLabel` | `string` | `'Data table'` |
|
|
647
|
+
| `showToolbar` | `boolean` | `true` |
|
|
648
|
+
| `searchable` | `boolean` | `true` |
|
|
649
|
+
| `searchPlaceholder` | `string` | `'Search…'` |
|
|
650
|
+
| `showFilters` | `boolean` | `false` |
|
|
651
|
+
| `filterPlaceholder` | `string` | `'Filter…'` |
|
|
652
|
+
| `filterAllLabel` | `string` | `'All'` |
|
|
653
|
+
| `emptyText` | `string` | `'No records found'` |
|
|
654
|
+
| `sortable` | `boolean` | `true` |
|
|
655
|
+
| `sort` | `TableSort \| null` | `null` |
|
|
656
|
+
| `search` | `string` | `''` |
|
|
657
|
+
| `filters` | `Record<string, string>` | `{}` |
|
|
658
|
+
| `page` | `number` | `1` |
|
|
659
|
+
| `pageSize` | `number` | `10` |
|
|
660
|
+
| `pageSizeOptions` | `number[]` | `[10, 20, 50, 100]` |
|
|
661
|
+
| `showPagination` | `boolean` | `true` |
|
|
662
|
+
| `showPageSize` | `boolean` | `true` |
|
|
663
|
+
| `showFirstLast` | `boolean` | `true` |
|
|
664
|
+
| `maxPageButtons` | `number` | `5` |
|
|
665
|
+
| `showFooter` | `boolean` | `true` |
|
|
666
|
+
| `selectionMode` | `'none' \| 'single' \| 'multi'` | `'none'` |
|
|
667
|
+
| `selectAllScope` | `'page' \| 'all'` | `'page'` |
|
|
668
|
+
| `selected` | `T[]` | `[]` |
|
|
669
|
+
| `selectOnRowClick` | `boolean` | `false` |
|
|
670
|
+
| `rowActions` | `TableRowAction<T>[]` | `[]` |
|
|
671
|
+
| `actionsHeader` | `string` | `'Actions'` |
|
|
672
|
+
| `actionsWidth` | `string` | `'120px'` |
|
|
673
|
+
| `rowClickable` | `boolean` | `false` |
|
|
674
|
+
| `rowClass` | `(row, index) => string \| string[] \| Record<string, boolean>` | — |
|
|
675
|
+
| `loading` | `boolean` | `false` |
|
|
676
|
+
| `loadingText` | `string` | `'Loading…'` |
|
|
677
|
+
| `striped` | `boolean` | `false` |
|
|
678
|
+
| `hoverable` | `boolean` | `true` |
|
|
679
|
+
| `bordered` | `boolean` | `false` |
|
|
680
|
+
| `dense` | `boolean` | `false` |
|
|
681
|
+
| `stickyHeader` | `boolean` | `false` |
|
|
682
|
+
| `maxHeight` | `string` | `''` |
|
|
683
|
+
| `copyable` | `boolean` | `false` |
|
|
684
|
+
| `showColumnPicker` | `boolean` | `false` |
|
|
685
|
+
| `showDensityToggle` | `boolean` | `false` |
|
|
686
|
+
| `storageKey` | `string` | `''` |
|
|
687
|
+
| `skeletonRows` | `number` | `6` |
|
|
688
|
+
| `stickySelection` | `boolean` | `false` |
|
|
689
|
+
| `stickyActions` | `boolean` | `false` |
|
|
690
|
+
|
|
691
|
+
### Outputs
|
|
692
|
+
|
|
693
|
+
| Output | Payload |
|
|
694
|
+
| --- | --- |
|
|
695
|
+
| `sortChange` | `TableSort \| null` |
|
|
696
|
+
| `searchChange` | `string` |
|
|
697
|
+
| `filterChange` | `Record<string, string>` |
|
|
698
|
+
| `filtersChange` | `Record<string, string>` |
|
|
699
|
+
| `pageChange` | `number` |
|
|
700
|
+
| `pageSizeChange` | `number` |
|
|
701
|
+
| `selectedChange` | `T[]` |
|
|
702
|
+
| `actionClick` | `TableActionEvent<T>` (`{ action, row, index }`) |
|
|
703
|
+
| `rowClick` | `TableRowEvent<T>` (`{ row, index, event }`) |
|
|
704
|
+
| `cellCopy` | `TableCellCopyEvent<T>` (`{ value, row, index, column }`) |
|
|
705
|
+
| `rowContextMenu` | `TableRowMenuEvent<T>` (`{ row, index, x, y, event }`) |
|
|
706
|
+
| `columnsChange` | `string[]` (visible column keys) |
|
|
707
|
+
| `densityChange` | `'comfortable' \| 'compact'` |
|
|
708
|
+
|
|
709
|
+
## License
|
|
710
|
+
|
|
711
|
+
MIT © iTHouse
|