@ithouse-bd/ngx-table 0.0.0-stage → 1.1.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.
@@ -0,0 +1,877 @@
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
+ - [Copy, context menu & presets](#copy-context-menu--presets)
18
+ - [Header menu, resize and reorder](#header-menu-resize-and-reorder)
19
+ - [Named views](#named-views)
20
+ - [Row detail](#row-detail)
21
+ - [CSV and Excel export](#csv-and-excel-export)
22
+ - [Footer totals](#footer-totals)
23
+ - [Keyboard grid](#keyboard-grid)
24
+ - [Loading and empty states](#loading-and-empty-states)
25
+ - [Server-side mode](#server-side-mode)
26
+ - [Programmatic API](#programmatic-api)
27
+ - [Accessibility](#accessibility)
28
+ - [Performance](#performance)
29
+ - [Troubleshooting](#troubleshooting)
30
+ - [Full input/output reference](#full-inputoutput-reference)
31
+
32
+ ![Table overview](docs/images/table-overview.svg)
33
+
34
+ ## Requirements
35
+
36
+ - Angular **20 or newer** (standalone components, signal inputs, `model()`)
37
+ - No CSS framework required; the component ships its own scoped styles
38
+
39
+ Install:
40
+
41
+ ```bash
42
+ npm install @ithouse-bd/ngx-table
43
+ ```
44
+
45
+ The library is standalone-only; import the component and any template directives you use:
46
+
47
+ ```typescript
48
+ import { TableComponent, TableCellDirective } from '@ithouse-bd/ngx-table';
49
+ ```
50
+
51
+ > **Projected templates:** the `ithTableCell`, `ithTableHeader`, `ithTableFilter`,
52
+ > `ithTableRowActions`, `ithTableToolbar`, `ithTableFooter`, `ithTableEmpty` and
53
+ > `ithTableRowMenu` directives are used in *your* template, so import the ones you use into
54
+ > your component.
55
+
56
+ ## Basic usage
57
+
58
+ ```typescript
59
+ interface Product {
60
+ id: number;
61
+ name: string;
62
+ category: string;
63
+ price: number;
64
+ stock: number;
65
+ active: boolean;
66
+ }
67
+
68
+ readonly columns: TableColumn<Product>[] = [
69
+ { key: 'name', header: 'Product', minWidth: '200px' },
70
+ { key: 'category', header: 'Category' },
71
+ { key: 'price', header: 'Price', align: 'right', formatter: (v) => `$${Number(v).toFixed(2)}` },
72
+ { key: 'stock', header: 'Stock', align: 'center' },
73
+ { key: 'active', header: 'Active', formatter: (v) => (v ? 'Yes' : 'No') },
74
+ ];
75
+ ```
76
+
77
+ ```html
78
+ <ith-table
79
+ title="Products"
80
+ countSuffix="products"
81
+ [data]="products"
82
+ [columns]="columns"
83
+ [pageSize]="20">
84
+ </ith-table>
85
+ ```
86
+
87
+ Defaults that matter:
88
+
89
+ | Option | Default |
90
+ | --- | --- |
91
+ | `mode` | `client` |
92
+ | `keyField` | `id` |
93
+ | `selectionMode` | `none` |
94
+ | `sortable` | `true` (per column) |
95
+ | `searchable` | `true` |
96
+ | `pageSize` | `10` |
97
+ | `pageSizeOptions` | `[10, 20, 50, 100]` |
98
+ | `hoverable` | `true` |
99
+ | `showToolbar` / `showFooter` | `true` |
100
+ | `showPagination` / `showPageSize` / `showFirstLast` | `true` |
101
+
102
+ ## Columns
103
+
104
+ `TableColumn<T>` controls both data access and rendering:
105
+
106
+ | Field | Type | Description |
107
+ | --- | --- | --- |
108
+ | `key` | `string` | Unique id. Also the template name (`ithTableCell="key"`). |
109
+ | `header` | `string` | Header label; defaults to `key`. |
110
+ | `field` | `string` | Dot-path to the value, e.g. `customer.name`. Defaults to `key`. |
111
+ | `sortable` | `boolean` | Per-column override of the table-level `sortable`. |
112
+ | `searchable` | `boolean` | Include in global search (default `true`). |
113
+ | `filterable` | `boolean` | Show a control in the filter row (default `true`). |
114
+ | `filterType` | `'text' \| 'number' \| 'date' \| 'select'` | Control used by the filter (default `text`). |
115
+ | `filterOptions` | `{ label, value }[]` | Options of a `select` filter. |
116
+ | `filterPlaceholder` | `string` | Placeholder for this column's control. |
117
+ | `filterPredicate` | `(cellValue, filterValue, row) => boolean` | Custom matching rule (wins over `filterType`). |
118
+ | `align` | `'left' \| 'center' \| 'right'` | Header and cell alignment. |
119
+ | `width`, `minWidth` | `string` | CSS sizing, e.g. `'120px'`, `'20%'`. |
120
+ | `hidden` | `boolean` | Keep the config but hide the column. |
121
+ | `headerClass`, `cellClass` | `string` \| `(row, index) => string \| string[] \| object` | Extra classes. |
122
+ | `formatter` | `(value, row, index) => string \| number` | Display value; also used for search/filter matching. |
123
+ | `sortFn` | `(a: T, b: T) => number` | Custom ascending comparator. |
124
+ | `searchValue` | `(row: T) => string` | Custom text for the global search. |
125
+ | `filterValue` | `(row: T) => string` | Custom text for the column filter. |
126
+ | `tooltip` | `boolean` | Show the full cell text as a native tooltip (default `true`). |
127
+ | `sticky` | `'start' \| 'end'` | Keep the column pinned while scrolling horizontally (declare a `width`). |
128
+
129
+ Nested values work out of the box:
130
+
131
+ ```typescript
132
+ { key: 'name', field: 'customer.name', header: 'Customer' }
133
+ ```
134
+
135
+ ## Sorting
136
+
137
+ Clicking a sortable header cycles **ascending → descending → unsorted**. Bind `sort` for
138
+ two-way control or listen to `sortChange`:
139
+
140
+ ```html
141
+ <ith-table
142
+ [data]="rows"
143
+ [columns]="columns"
144
+ [sort]="sort"
145
+ (sortChange)="sort = $event">
146
+ </ith-table>
147
+ ```
148
+
149
+ ```typescript
150
+ sort: TableSort | null = { key: 'price', direction: 'desc' };
151
+ ```
152
+
153
+ `TableSort` is `{ key: string; direction: 'asc' | 'desc' }`. Disable sorting table-wide with
154
+ `[sortable]="false"`, or per column with `{ sortable: false }`.
155
+
156
+ ### Custom comparators
157
+
158
+ ```typescript
159
+ {
160
+ key: 'priority',
161
+ header: 'Priority',
162
+ sortFn: (a, b) => priorityWeight[a.priority] - priorityWeight[b.priority],
163
+ }
164
+ ```
165
+
166
+ Sorting compares raw values by default: numbers numerically, dates by time, strings with
167
+ `localeCompare` (`numeric: true`, case-insensitive).
168
+
169
+ ## Search and filters
170
+
171
+ `searchable` (default `true`) renders a search input in the toolbar. It matches **any**
172
+ searchable column; searching is debounced by Angular change detection, not by a timer, so
173
+ bind `search` in server mode when you need throttling.
174
+
175
+ ```html
176
+ <ith-table [data]="rows" [columns]="columns" [(search)]="term"></ith-table>
177
+ ```
178
+
179
+ ### Per-column filters
180
+
181
+ ```html
182
+ <ith-table [data]="rows" [columns]="columns" [showFilters]="true"></ith-table>
183
+ ```
184
+
185
+ A second header row appears with a control for **every column**. Each column decides what
186
+ it renders through `filterType`:
187
+
188
+ ```typescript
189
+ const columns: TableColumn<Order>[] = [
190
+ // text (default): keeps rows whose display text contains the input
191
+ { key: 'customer', header: 'Customer' },
192
+ { key: 'customer', field: 'customer.name', header: 'Customer', filterPlaceholder: 'Search…' },
193
+
194
+ // number: exact match on the numeric value
195
+ { key: 'quantity', header: 'Qty', filterType: 'number' },
196
+
197
+ // date: exact match on yyyy-mm-dd
198
+ { key: 'createdAt', field: 'createdAt', header: 'Created', filterType: 'date' },
199
+
200
+ // select: exact match, rendered as a dropdown
201
+ {
202
+ key: 'status',
203
+ header: 'Status',
204
+ filterType: 'select',
205
+ filterOptions: [
206
+ { label: 'Paid', value: 'paid' },
207
+ { label: 'Pending', value: 'pending' },
208
+ ],
209
+ },
210
+
211
+ // custom matching: any rule you like
212
+ {
213
+ key: 'total',
214
+ header: 'Total',
215
+ filterType: 'number',
216
+ filterPredicate: (value, term) => Number(value) >= Number(term), // “total ≥ term”
217
+ },
218
+
219
+ // no filter control at all
220
+ { key: 'notes', header: 'Notes', filterable: false },
221
+ ];
222
+ ```
223
+
224
+ Select filters show an empty option labelled `[filterAllLabel]="'All'"`. Opt a column out
225
+ with `{ filterable: false }`, hide the whole row with `[showFilters]="false"` (the default),
226
+ or replace one control with your own template:
227
+
228
+ ```html
229
+ <ng-template ithTableFilter="status" let-value let-setFn="setValue">
230
+ <select class="my-filter" [value]="value" (change)="setFn($any($event.target).value)">
231
+ <option value="">Everything</option>
232
+ <option value="paid">Paid</option>
233
+ <option value="pending">Pending</option>
234
+ </select>
235
+ </ng-template>
236
+ ```
237
+
238
+ Context: `$implicit`/`value` (current filter text), `column`, `setValue(value: string)`.
239
+ Projected templates are styled by **your** component, so give them their own classes.
240
+
241
+ Filters are exposed as `filters` (`Record<columnKey, string>`), two-way bindable, and as the
242
+ `filterChange` output:
243
+
244
+ ```html
245
+ <ith-table [(filters)]="filters" (filterChange)="load()"></ith-table>
246
+ ```
247
+
248
+ In **client mode** search and filters reset the table to page 1 automatically. In **server
249
+ mode** nothing is filtered locally and the table never moves the page on its own: it passes
250
+ the whole `filterChange` record to you, and your handler should reset the page while it
251
+ fetches the filtered page back.
252
+
253
+ The empty state offers a “Clear search & filters” action.
254
+
255
+ Matching rules: `text` matches the formatted cell text, `number` compares numerically
256
+ (`12`, `12.0` and `012` all match 12), `date` compares the calendar date so an ISO string
257
+ such as `2026-10-05T23:00:00Z` is never shifted by a time zone, and `select` matches the
258
+ option value exactly.
259
+
260
+ ## Pagination
261
+
262
+ The footer shows `Showing 1–10 of 13`, the `totalLabel` count, a numbered page window,
263
+ first/previous/next/last buttons and a rows-per-page selector.
264
+
265
+ ```html
266
+ <ith-table
267
+ [data]="rows"
268
+ [columns]="columns"
269
+ [(page)]="page"
270
+ [(pageSize)]="pageSize"
271
+ [pageSizeOptions]="[5, 10, 25, 100]"
272
+ [maxPageButtons]="7"
273
+ (pageChange)="onPage($event)">
274
+ </ith-table>
275
+ ```
276
+
277
+ `pageChange` emits the new page number, `pageSizeChange` the new page size. All three of
278
+ `page`, `pageSize` and `pageSizeOptions` can be bound; hide parts of the footer with
279
+ `[showPagination]="false"`, `[showPageSize]="false"` or `[showFirstLast]="false"`.
280
+
281
+ If data shrinks, the current page is clamped to the last available page automatically.
282
+
283
+ ## Selection
284
+
285
+ ```html
286
+ <ith-table
287
+ [data]="rows"
288
+ [columns]="columns"
289
+ selectionMode="multi"
290
+ [(selected)]="selected">
291
+ </ith-table>
292
+ ```
293
+
294
+ | Input | Description |
295
+ | --- | --- |
296
+ | `selectionMode` | `'none'`, `'single'` or `'multi'` |
297
+ | `selectAllScope` | `'page'` (default) selects the visible page, `'all'` selects every filtered row |
298
+ | `selectOnRowClick` | Click anywhere on a row to toggle it (default `false`) |
299
+ | `keyField` | Row identity; selection survives sorting, filtering and paging by key |
300
+ | `selected` | Two-way bindable array of selected rows |
301
+
302
+ `selectedChange` emits the selected rows. Header checkbox reflects `allPageSelected()` and
303
+ shows an indeterminate state when only some rows of the page are selected.
304
+
305
+ Selection across pages is preserved by key. For server mode, keys are compared to the rows
306
+ currently in `selected`, so keep the objects you put there.
307
+
308
+ Public helpers: `toggleRow(row, checked)`, `toggleAll(checked)`, `selectRow(row)`,
309
+ `deselectRow(row)`, `clearSelection()`, `isSelected(row)`.
310
+
311
+ ## Row actions
312
+
313
+ ```typescript
314
+ readonly actions: TableRowAction<Order>[] = [
315
+ { id: 'view', label: 'View', icon: '👁' },
316
+ { id: 'ship', label: 'Ship', disabled: (row) => row.status !== 'paid', hidden: (row) => row.cancelled },
317
+ { id: 'cancel', label: 'Cancel', class: 'is-danger' },
318
+ ];
319
+ ```
320
+
321
+ ```html
322
+ <ith-table
323
+ [data]="orders"
324
+ [columns]="columns"
325
+ [rowActions]="actions"
326
+ actionsHeader="Actions"
327
+ actionsWidth="180px"
328
+ (actionClick)="onAction($event)">
329
+ </ith-table>
330
+ ```
331
+
332
+ ```typescript
333
+ onAction(event: TableActionEvent<Order>): void {
334
+ const { action, row, index } = event;
335
+ if (action.id === 'view') this.router.navigate(['/orders', row.id]);
336
+ }
337
+ ```
338
+
339
+ The actions column is rendered only when `rowActions` is non-empty **or** a
340
+ `#ithTableRowActions` template exists. Buttons stop click propagation, so row clicks (and
341
+ `selectOnRowClick`) are not triggered.
342
+
343
+ ## Custom templates
344
+
345
+ All templates are optional. Import the matching directives in your component.
346
+
347
+ ### Cell — `ithTableCell="key"`
348
+
349
+ ```html
350
+ <ng-template ithTableCell="status" let-row let-value="value" let-index="index">
351
+ <span class="badge" [class.bg-success]="value === 'active'">{{ value }}</span>
352
+ </ng-template>
353
+ ```
354
+
355
+ Context: `$implicit`/`row`, `column`, `value`, `index`.
356
+
357
+ ### Header — `ithTableHeader="key"`
358
+
359
+ ```html
360
+ <ng-template ithTableHeader="price" let-column="column">
361
+ <span class="d-inline-flex align-items-center gap-1">
362
+ {{ column.header }} <small class="text-muted">USD</small>
363
+ </span>
364
+ </ng-template>
365
+ ```
366
+
367
+ Context: `$implicit`/`column`.
368
+
369
+ ### Filter control — `ithTableFilter="key"`
370
+
371
+ ```html
372
+ <ng-template ithTableFilter="customer" let-value let-setFn="setValue" let-column="column">
373
+ <input class="search" [value]="value" (input)="setFn($any($event.target).value)" />
374
+ </ng-template>
375
+ ```
376
+
377
+ Context: `$implicit`/`value`, `column`, `setValue`. Changing the value behaves exactly like
378
+ the built-in control (server mode emits `filterChange`, page resets to 1).
379
+
380
+ ### Row actions — `ithTableRowActions`
381
+
382
+ ```html
383
+ <ng-template ithTableRowActions let-row let-index="index">
384
+ <button type="button" class="btn btn-sm" (click)="edit(row)">Edit</button>
385
+ <button type="button" class="btn btn-sm btn-danger" (click)="remove(row, index)">Delete</button>
386
+ </ng-template>
387
+ ```
388
+
389
+ Context: `$implicit`/`row`, `index`.
390
+
391
+ ### Toolbar — `ithTableToolbar`
392
+
393
+ Rendered next to the title and count badge:
394
+
395
+ ```html
396
+ <ng-template ithTableToolbar let-total="total" let-selected="selected">
397
+ <button class="btn btn-sm btn-primary" (click)="exportRows()">
398
+ Export {{ total }}
399
+ </button>
400
+ @if (selected.length) {
401
+ <button class="btn btn-sm btn-outline-danger" (click)="bulkDelete()">
402
+ Delete {{ selected.length }}
403
+ </button>
404
+ }
405
+ </ng-template>
406
+ ```
407
+
408
+ Context: `rows` (current page), `total`, `selected`, `search`.
409
+
410
+ ### Footer — `ithTableFooter`
411
+
412
+ Replaces the default summary **only**; pagination controls stay. Context adds `page`,
413
+ `pageSize`, `pageCount`:
414
+
415
+ ```html
416
+ <ng-template ithTableFooter let-page="page" let-page-count="pageCount" let-total="total">
417
+ <span>Page {{ page }} of {{ pageCount }} — {{ total }} records</span>
418
+ </ng-template>
419
+ ```
420
+
421
+ ### Empty — `ithTableEmpty`
422
+
423
+ ```html
424
+ <ng-template ithTableEmpty>
425
+ <div class="text-center py-4">
426
+ <p class="mb-2">Nothing here yet.</p>
427
+ <button class="btn btn-primary" (click)="create()">Create the first record</button>
428
+ </div>
429
+ </ng-template>
430
+ ```
431
+
432
+ ## Copy, context menu & presets
433
+
434
+ ### Copy
435
+
436
+ ```html
437
+ <ith-table [data]="rows" [columns]="columns" [copyable]="true"
438
+ (cellCopy)="onCopy($event)"></ith-table>
439
+ ```
440
+
441
+ - A copy button appears on cell hover; `Ctrl`/`Cmd` + `C` copies the focused cell too.
442
+ - `(cellCopy)` emits `{ value, row, index, column }`; `column` is `null` when a full row was
443
+ copied with `copyRow(row, index)`.
444
+
445
+ ### Right-click menu
446
+
447
+ ```html
448
+ <ith-table [data]="rows" [columns]="columns">
449
+ <ng-template ithTableRowMenu let-row let-index="index">
450
+ <button type="button" (click)="open(row)">Open</button>
451
+ <button type="button" (click)="remove(row, index)">Delete</button>
452
+ </ng-template>
453
+ </ith-table>
454
+ ```
455
+
456
+ - Right-click or `Shift+F10` / the context-menu key emits `rowContextMenu`
457
+ (`{ row, index, x, y, event }`) and renders the template in a fixed panel at the pointer.
458
+ - The panel closes on outside click or `Escape`; `closeRowMenu()` closes it from code.
459
+ - Without an `ithTableRowMenu` template the event is still emitted (for your own popover)
460
+ and the browser menu is left alone.
461
+
462
+ ### Column visibility, density and presets
463
+
464
+ ```html
465
+ <ith-table [data]="rows" [columns]="columns"
466
+ [showColumnPicker]="true"
467
+ [showDensityToggle]="true"
468
+ storageKey="students-table"
469
+ (columnsChange)="onColumns($event)"
470
+ (densityChange)="onDensity($event)"></ith-table>
471
+ ```
472
+
473
+ - The "Columns" popover toggles visibility without touching the column config; at least one
474
+ column always stays visible.
475
+ - With `storageKey`, the whole layout is restored from `localStorage` on the next visit:
476
+ hidden columns, density, order, widths and pinning (the stored JSON is versioned, and an old
477
+ 1.0.0 `{ hidden, density }` value is still read). Call `resetColumns()` to clear it.
478
+ - `dense` still forces compact rows; the toggle only switches the runtime density.
479
+
480
+ ### Header menu, resize and reorder
481
+
482
+ ```html
483
+ <ith-table [data]="rows" [columns]="columns"
484
+ [resizable]="true" [reorderable]="true"
485
+ [showColumnMenu]="true"
486
+ (columnStateChange)="save($event)"></ith-table>
487
+ ```
488
+
489
+ - Every header shows a `⋮` button (on hover, or always on focus) opening a menu with sort
490
+ ascending/descending, clear sort, pin to left/right, unpin, fit to content and hide column.
491
+ Each item respects the column flags: `sortable`, `pinnable`, `hideable`.
492
+ - All popovers are rendered with `position: fixed` and positioned from the trigger's
493
+ rectangle, so the toolbar's horizontal scroll box and the table's `overflow` can never clip
494
+ them.
495
+ - `resizable` adds a pointer drag handle on the right edge of each header (minimum 56 px);
496
+ `autosizeColumn(key)` or "Fit to content" sizes a column from its widest rendered value.
497
+ - `reorderable` drags a header onto another header; hidden columns keep their slot.
498
+ - `columnStateChange` emits `TablePresetState` — `{ hidden, density, order, widths, pinned }` —
499
+ whenever the user changes the layout.
500
+ - Per-column opt-outs: `sticky: 'start' | 'end'` (initial pin), `pinnable: false`,
501
+ `hideable: false`.
502
+
503
+ ### Named views
504
+
505
+ ```html
506
+ <ith-table [data]="rows" [columns]="columns" [showViews]="true"
507
+ storageKey="orders-table"></ith-table>
508
+ ```
509
+
510
+ The Views menu lists saved layouts ("Compact view", "Finance view" …), lets the user save the
511
+ current layout under a name, apply one with a click and delete one with `×`. Views live in the
512
+ same `storageKey` entry, and the active view stays highlighted.
513
+
514
+ ### Filter chips
515
+
516
+ When `search()` or any column filter is active, `.ith-table-chips` shows one removable chip per
517
+ filter plus "Clear all". `showFilterChips` (default `true`) disables the row; `removeChip()` and
518
+ `clearQuery()` are also available programmatically.
519
+
520
+ ### Selection bar
521
+
522
+ ```typescript
523
+ bulk: TableSelectionAction<Row>[] = [
524
+ { id: 'export', label: 'Export selected' },
525
+ { id: 'delete', label: 'Delete', class: 'is-danger' },
526
+ ];
527
+ ```
528
+
529
+ ```html
530
+ <ith-table [data]="rows" [columns]="columns" selectionMode="multi"
531
+ [selectionActions]="bulk" (selectionAction)="run($event)"></ith-table>
532
+ ```
533
+
534
+ As soon as one row is selected a bar appears above the table with the count, your actions and
535
+ "Clear selection". `(selectionAction)` emits `{ action, rows }`.
536
+
537
+ ### Row detail
538
+
539
+ ```html
540
+ <ith-table [data]="rows" [columns]="columns" rowDetailTrigger="button">
541
+ <ng-template ithTableRowDetail let-row let-close="close">
542
+ <dl class="detail">
543
+ <dt>Email</dt><dd>{{ row.email }}</dd>
544
+ </dl>
545
+ <button type="button" (click)="close()">Close</button>
546
+ </ng-template>
547
+ </ith-table>
548
+ ```
549
+
550
+ - `rowDetailTrigger="button"` adds a chevron cell (rotates when open); `"row"` expands on row
551
+ click; `"none"` disables expansion.
552
+ - The panel renders on its own full-width row under the row, and the template receives
553
+ `{ $implicit, row, index, close }`.
554
+
555
+ ### CSV and Excel export
556
+
557
+ ```html
558
+ <ith-table [data]="rows" [columns]="columns" [showExport]="true"
559
+ exportFileName="orders"
560
+ (csvExport)="onCsv($event)"
561
+ (exportFile)="onFile($event)"></ith-table>
562
+ ```
563
+
564
+ `showExport` renders one toolbar button that opens a two-item menu:
565
+
566
+ | Item | Method | Result |
567
+ | --- | --- | --- |
568
+ | **Excel** | `downloadExcel()` / `toExcel()` | `.xlsx` workbook: bold frozen header row, autofilter, sized columns |
569
+ | **CSV** | `downloadCsv()` / `toCsv()` | `.csv`, UTF-8 with BOM so Excel keeps the encoding |
570
+
571
+ - Both paths write the visible columns in the user's order and the formatted cell text, and
572
+ use the selected rows when there is a selection — otherwise every filtered row (not just the
573
+ current page).
574
+ - `toCsv()` returns the text, `toExcel()` returns a `Blob`; `exportAs('csv' | 'xlsx')` runs the
575
+ same logic as the menu. `(csvExport)` emits the CSV string, `(exportFile)` emits
576
+ `{ format, fileName, blob, rows }` for both formats (upload it to your API instead of saving).
577
+ - The `.xlsx` writer (`buildXlsxBlob()` from the package) is a small ZIP + OOXML writer with no
578
+ runtime dependency; it is exported separately in case you want to reuse it.
579
+ - CSV values containing `,` `;` `"` or a newline are quoted and escaped.
580
+ - Excel cells are written as text, so leading zeros in codes such as `260029` survive.
581
+
582
+ ### Footer totals
583
+
584
+ ```typescript
585
+ columns: TableColumn<Order>[] = [
586
+ { key: 'customer', header: 'Customer' },
587
+ { key: 'total', header: 'Total', align: 'right', aggregate: 'sum' },
588
+ { key: 'qty', header: 'Qty', aggregate: { type: 'avg', label: 'Average' } },
589
+ { key: 'id', header: '#', aggregate: 'count' },
590
+ ];
591
+ ```
592
+
593
+ `sum`, `avg`, `min`, `max` and `count` are computed over the filtered rows (the loaded page in
594
+ server mode) and rendered in a `<tfoot>` row that keeps the column alignment, sticky columns
595
+ and the density. `aggregate.label` renames the caption and `aggregate.format(value)` controls
596
+ the number formatting.
597
+
598
+ ### Keyboard grid
599
+
600
+ `keyboardNavigation` (default `true`) gives the body a single tab stop and grid navigation:
601
+
602
+ | Key | Action |
603
+ | --- | --- |
604
+ | `↑` `↓` `←` `→` | Move one cell |
605
+ | `Home` / `End` | First / last cell of the row |
606
+ | `Ctrl+Home` / `Ctrl+End` | First cell / last cell of the page |
607
+ | `PageUp` / `PageDown` | Move one page of rows |
608
+ | `Space` | Toggle selection of the row |
609
+ | `Ctrl/Cmd+C` | Copy the focused cell (with `copyable`) |
610
+ | `Shift+F10` / context-menu key | Emit `rowContextMenu` |
611
+
612
+ ### Sticky columns and tooltips
613
+
614
+ ```typescript
615
+ columns: TableColumn<Row>[] = [
616
+ { key: 'name', header: 'Name', width: '220px', sticky: 'start' },
617
+ { key: 'email', header: 'Email' },
618
+ { key: 'notes', header: 'Notes', tooltip: true },
619
+ ];
620
+ ```
621
+
622
+ - `sticky: 'start' | 'end'` pins that column; declare a pixel `width` so the next sticky
623
+ column can be offset.
624
+ - `[stickySelection]="true"` / `[stickyActions]="true"` pin the checkbox and actions columns.
625
+ - `tooltip: false` disables the native title for a column.
626
+
627
+ ## Loading and empty states
628
+
629
+ ```html
630
+ <ith-table
631
+ [data]="rows"
632
+ [columns]="columns"
633
+ [loading]="loading()"
634
+ loadingText="Fetching orders…"
635
+ emptyText="No orders for this period">
636
+ </ith-table>
637
+ ```
638
+
639
+ - With no rows, a spinner and `loadingText` replace the empty state.
640
+ - With rows, a translucent overlay keeps the current rows visible while loading.
641
+ - `hasQuery()` in the empty state switches the message to “No records match your search.”
642
+ and offers a clear action.
643
+
644
+ ## Server-side mode
645
+
646
+ ```typescript
647
+ readonly pageRows = signal<Order[]>([]);
648
+ readonly total = signal(0);
649
+ readonly loading = signal(false);
650
+ readonly page = signal(1);
651
+ readonly pageSize = signal(10);
652
+ readonly sort = signal<TableSort | null>({ key: 'createdAt', direction: 'desc' });
653
+ readonly search = signal('');
654
+
655
+ constructor() {
656
+ effect(() => {
657
+ // Any query change triggers a reload; signals make this zoneless-safe.
658
+ void this.fetch(this.page(), this.pageSize(), this.sort(), this.search());
659
+ });
660
+ }
661
+
662
+ private async fetch(page: number, pageSize: number, sort: TableSort | null, search: string) {
663
+ this.loading.set(true);
664
+ const result = await this.api.orders({ page, pageSize, sort, search });
665
+ this.pageRows.set(result.items);
666
+ this.total.set(result.total);
667
+ this.loading.set(false);
668
+ }
669
+ ```
670
+
671
+ ```html
672
+ <ith-table
673
+ mode="server"
674
+ [data]="pageRows()"
675
+ [total]="total()"
676
+ [loading]="loading()"
677
+ [columns]="columns"
678
+ [page]="page()"
679
+ [pageSize]="pageSize()"
680
+ [sort]="sort()"
681
+ [search]="search()"
682
+ (pageChange)="page.set($event)"
683
+ (pageSizeChange)="pageSize.set($event); page.set(1)"
684
+ (sortChange)="sort.set($event)"
685
+ (searchChange)="search.set($event); page.set(1)">
686
+ </ith-table>
687
+ ```
688
+
689
+ Notes:
690
+
691
+ - In server mode the table renders exactly `[data]`; it never slices or re-sorts.
692
+ - `[total]` drives the page count and the footer range. Fall back to `data.length` when it is `0`.
693
+ - The table owns the page in **client** mode only (query changes restart at page 1). In
694
+ server mode reset `page` yourself in the `searchChange` / `filterChange` /
695
+ `pageSizeChange` handlers — that keeps a query change to a single request.
696
+ - `selectAllScope="all"` can only select the rows you have loaded; for true “select all”
697
+ keep a server-side flag instead.
698
+
699
+ ## Programmatic API
700
+
701
+ ```typescript
702
+ @ViewChild(TableComponent) table!: TableComponent<Order>;
703
+ ```
704
+
705
+ | Method | Description |
706
+ | --- | --- |
707
+ | `goToPage(page)` | Clamp and navigate |
708
+ | `nextPage()` / `previousPage()` / `firstPage()` / `lastPage()` | Navigation helpers |
709
+ | `toggleSort(column)` | Cycle a column's sort state |
710
+ | `toggleRow(row, checked)` / `toggleAll(checked)` | Selection |
711
+ | `selectRow(row)` / `deselectRow(row)` / `clearSelection()` | Selection helpers |
712
+ | `isSelected(row)` / `rowKey(row)` | Selection inspection |
713
+ | `clearSearch()` / `clearFilters()` / `clearQuery()` | Reset search state |
714
+ | `setColumnVisible(key, visible)` / `canHide(key)` | Column visibility |
715
+ | `resetColumns()` | Restore the default layout |
716
+ | `pinColumn(key, 'start' \| 'end' \| null)` | Runtime pinning |
717
+ | `autosizeColumn(key)` | Fit a column to its content |
718
+ | `moveColumn(from, to)` | Reorder two columns |
719
+ | `setDensity(density)` / `toggleDensity()` | Comfortable vs compact rows |
720
+ | `toggleRowDetail(row)` / `isRowExpanded(row)` | Row detail panel |
721
+ | `toCsv()` / `toExcel()` | CSV text / `.xlsx` blob |
722
+ | `downloadCsv()` / `downloadExcel()` / `exportAs(format)` | Downloads |
723
+ | `saveView()` / `applyView(name)` / `deleteView(name, event)` | Named layouts |
724
+ | `toggleColumnPicker()` / `toggleViews()` | Open the toolbar popovers |
725
+
726
+ Expose `sort`, `search`, `page`, `pageSize`, `selected` and `filters` publicly to reset
727
+ them from the parent.
728
+
729
+ ## Accessibility
730
+
731
+ - Native `<table>`, `<thead>`/`<tbody>`, `<th scope="col">` markup.
732
+ - `aria-sort` on sortable headers (`ascending` / `descending` / `none`).
733
+ - Header and row checkboxes have explicit `aria-label`s; the header checkbox supports the
734
+ indeterminate state.
735
+ - Pagination is a `<nav aria-label="Pagination">` with labelled first/previous/next/last
736
+ buttons and `aria-current="page"` on the active page number.
737
+ - Sort headers and page buttons are real `<button>`s, so keyboard and screen readers work.
738
+ - Clickable rows (`rowClickable` / `selectOnRowClick`) are focusable and activate with
739
+ `Enter` or `Space`, exactly like a mouse click.
740
+ - Selectable rows expose `aria-selected`; the header checkbox reflects “all on page” and
741
+ the indeterminate state.
742
+ - `aria-busy` reflects `loading`, the loading/empty cell is `aria-live="polite"`, and
743
+ `aria-label` names the table (`ariaLabel` input).
744
+ - `prefers-reduced-motion` disables row, button and input transitions.
745
+
746
+ ## Performance
747
+
748
+ - Set `keyField` to a real unique field so `@for` tracks rows by key.
749
+ - Use `mode="server"` for large datasets instead of paging thousands of rows in the browser.
750
+ - Provide `track`-friendly stable row objects; the table never mutates your array.
751
+ - Avoid heavy work inside `formatter` / `cellClass` callbacks; they run per rendered cell.
752
+
753
+ ## Troubleshooting
754
+
755
+ **Template directives are ignored / “not a known property”**
756
+ Import `TableCellDirective` (and friends) into the component that declares the template.
757
+
758
+ **Styles don’t show up**
759
+ Component styles are scoped; do not set `encapsulation: ViewEncapsulation.None` on the
760
+ consumer and avoid `display: none` on the host. The table needs its host `display: block`.
761
+
762
+ **Angular budget warning for component styles**
763
+ The table stylesheet is ~36 kB uncompressed (~6 kB gzipped). If your Angular project uses
764
+ the default `anyComponentStyle` budget (8 kB), raise it:
765
+
766
+ ```json
767
+ {
768
+ "type": "anyComponentStyle",
769
+ "maximumWarning": "16kb",
770
+ "maximumError": "20kb"
771
+ }
772
+ ```
773
+
774
+ **Page resets unexpectedly**
775
+ In client mode changing `search`, `filters`, `sort` or `pageSize` returns to page 1 on
776
+ purpose. In server mode the table never resets the page — if it jumps, your own handler
777
+ (or a clamped `page` after the total shrank) is doing it.
778
+
779
+ **Selection is lost after refetch (server mode)**
780
+ Rows are compared by `keyField`; pass the same row objects (or at least the same keys) in
781
+ `[(selected)]`, and don’t rebuild selected objects with different ids.
782
+
783
+ ## Full input/output reference
784
+
785
+ ### Inputs
786
+
787
+ | Input | Type | Default |
788
+ | --- | --- | --- |
789
+ | `data` | `T[]` | `[]` |
790
+ | `columns` | `TableColumn<T>[]` | `[]` |
791
+ | `keyField` | `string` | `'id'` |
792
+ | `mode` | `'client' \| 'server'` | `'client'` |
793
+ | `total` | `number` | `0` |
794
+ | `title` | `string` | `''` |
795
+ | `countSuffix` | `string` | `'items'` |
796
+ | `totalLabel` | `string` | `'Total Found'` |
797
+ | `ariaLabel` | `string` | `'Data table'` |
798
+ | `showToolbar` | `boolean` | `true` |
799
+ | `searchable` | `boolean` | `true` |
800
+ | `searchPlaceholder` | `string` | `'Search…'` |
801
+ | `showFilters` | `boolean` | `false` |
802
+ | `filterPlaceholder` | `string` | `'Filter…'` |
803
+ | `filterAllLabel` | `string` | `'All'` |
804
+ | `emptyText` | `string` | `'No records found'` |
805
+ | `sortable` | `boolean` | `true` |
806
+ | `sort` | `TableSort \| null` | `null` |
807
+ | `search` | `string` | `''` |
808
+ | `filters` | `Record<string, string>` | `{}` |
809
+ | `page` | `number` | `1` |
810
+ | `pageSize` | `number` | `10` |
811
+ | `pageSizeOptions` | `number[]` | `[10, 20, 50, 100]` |
812
+ | `showPagination` | `boolean` | `true` |
813
+ | `showPageSize` | `boolean` | `true` |
814
+ | `showFirstLast` | `boolean` | `true` |
815
+ | `maxPageButtons` | `number` | `5` |
816
+ | `showFooter` | `boolean` | `true` |
817
+ | `selectionMode` | `'none' \| 'single' \| 'multi'` | `'none'` |
818
+ | `selectAllScope` | `'page' \| 'all'` | `'page'` |
819
+ | `selected` | `T[]` | `[]` |
820
+ | `selectOnRowClick` | `boolean` | `false` |
821
+ | `rowActions` | `TableRowAction<T>[]` | `[]` |
822
+ | `actionsHeader` | `string` | `'Actions'` |
823
+ | `actionsWidth` | `string` | `'120px'` |
824
+ | `rowClickable` | `boolean` | `false` |
825
+ | `rowClass` | `(row, index) => string \| string[] \| Record<string, boolean>` | — |
826
+ | `loading` | `boolean` | `false` |
827
+ | `loadingText` | `string` | `'Loading…'` |
828
+ | `striped` | `boolean` | `false` |
829
+ | `hoverable` | `boolean` | `true` |
830
+ | `bordered` | `boolean` | `false` |
831
+ | `dense` | `boolean` | `false` |
832
+ | `stickyHeader` | `boolean` | `false` |
833
+ | `maxHeight` | `string` | `''` |
834
+ | `copyable` | `boolean` | `false` |
835
+ | `showColumnPicker` | `boolean` | `false` |
836
+ | `showDensityToggle` | `boolean` | `false` |
837
+ | `storageKey` | `string` | `''` |
838
+ | `skeletonRows` | `number` | `6` |
839
+ | `minRows` | `number` | `4` |
840
+ | `stickySelection` | `boolean` | `false` |
841
+ | `stickyActions` | `boolean` | `false` |
842
+ | `showFilterChips` | `boolean` | `true` |
843
+ | `selectionActions` | `TableSelectionAction<T>[]` | `[]` |
844
+ | `showColumnMenu` | `boolean` | `true` |
845
+ | `showExport` | `boolean` | `false` |
846
+ | `exportFileName` | `string` | `'table'` |
847
+ | `showViews` | `boolean` | `false` |
848
+ | `resizable` | `boolean` | `false` |
849
+ | `reorderable` | `boolean` | `false` |
850
+ | `keyboardNavigation` | `boolean` | `true` |
851
+ | `rowDetailTrigger` | `'button' \| 'row' \| 'none'` | `'button'` |
852
+
853
+ ### Outputs
854
+
855
+ | Output | Payload |
856
+ | --- | --- |
857
+ | `sortChange` | `TableSort \| null` |
858
+ | `searchChange` | `string` |
859
+ | `filterChange` | `Record<string, string>` |
860
+ | `filtersChange` | `Record<string, string>` |
861
+ | `pageChange` | `number` |
862
+ | `pageSizeChange` | `number` |
863
+ | `selectedChange` | `T[]` |
864
+ | `actionClick` | `TableActionEvent<T>` (`{ action, row, index }`) |
865
+ | `rowClick` | `TableRowEvent<T>` (`{ row, index, event }`) |
866
+ | `cellCopy` | `TableCellCopyEvent<T>` (`{ value, row, index, column }`) |
867
+ | `rowContextMenu` | `TableRowMenuEvent<T>` (`{ row, index, x, y, event }`) |
868
+ | `columnsChange` | `string[]` (visible column keys) |
869
+ | `densityChange` | `'comfortable' \| 'compact'` |
870
+ | `columnStateChange` | `TablePresetState` (`{ hidden, density, order, widths, pinned }`) |
871
+ | `selectionAction` | `TableSelectionActionEvent<T>` (`{ action, rows }`) |
872
+ | `csvExport` | `string` (the generated CSV) |
873
+ | `exportFile` | `TableExportEvent<T>` (`{ format, fileName, blob, rows }`) |
874
+
875
+ ## License
876
+
877
+ MIT © iTHouse