@su-labs/table 0.0.0-stage → 19.1.1
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 +53 -0
- package/LICENSE +21 -0
- package/README.md +379 -2
- package/fesm2022/su-labs-table.mjs +713 -0
- package/fesm2022/su-labs-table.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/table-cell.directive.d.ts +22 -0
- package/lib/table-field.component.d.ts +16 -0
- package/lib/table-paginator.component.d.ts +15 -0
- package/lib/table-pin-icon.component.d.ts +6 -0
- package/lib/table-pin.directive.d.ts +16 -0
- package/lib/table-toolbar.component.d.ts +48 -0
- package/lib/table.component.d.ts +187 -0
- package/package.json +52 -3
- package/public-api.d.ts +8 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [22.1.1] - 2026-11-15
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- The heading pin of a column set up with `pinned: 'end'` pins it back to the end instead of the start
|
|
12
|
+
|
|
13
|
+
## [22.1.0]
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- Pinned columns: `pinned: 'start' | 'end'` on a column keeps it in view while the others scroll, with a soft shadow on its edge while columns pass under it; the move handles and checkboxes stay with columns pinned to the start, the actions with those pinned to the end
|
|
17
|
+
- A pin in the heading of pinned and pinnable columns (`pinnable: true`) pins the column to the start or unpins it (a toggle, announced)
|
|
18
|
+
- `columnControls`: a Columns button with a menu to show, hide, pin and unpin columns: a search for long lists, a Select all checkbox (partly checked while some columns are hidden), a checkbox for each column and a toggle beside it that shows or hides the column's heading pin; Escape or a click outside closes it
|
|
19
|
+
- When the pinned columns would leave too little room to scroll the rest (e.g. on a phone), they stop sticking until there's room
|
|
20
|
+
- `--su-table-pinned-background` and `--su-table-pinned-shadow`
|
|
21
|
+
- Pinned columns show a pin in their heading and a thin line on their edge, so they read as pinned before anything scrolls; `--su-table-pinned-border`
|
|
22
|
+
- Pagination: `pageSize` and `pageSizes` show the rows a page at a time, with a paginator under the table (rows per page, the range on screen, previous and next, announced); `pageChange` emits `{ page, pageSize }`
|
|
23
|
+
- The select-all checkbox selects the rows of the current page; the selection is kept across pages
|
|
24
|
+
- Pinned rows: `rowPinning` adds a Pin button to each row (a toggle, announced) that keeps it above the others on every page, tinted and set off by a line; `pinnedRows` sets the starting pins and `pinnedRowsChange` emits their ids
|
|
25
|
+
- `--su-table-pinned-row-background` and `--su-table-pinned-row-border`
|
|
26
|
+
- Search: `searchable` adds a search box above the table that narrows the rows by the text they show, ignoring case and accents (every word must match), once typing pauses; the number of matches is announced, Escape clears it, pinned rows stay, and reordering is off meanwhile; `searchChange` emits the query
|
|
27
|
+
- The search box and the Columns button share a bar above the table
|
|
28
|
+
- Show and hide columns: `hidden: true` starts a column out of view (its field stays in the row data and comes back on save), with a checkbox for each column in the Columns menu; the last column on view stays shown, and hidden columns are left out of the search
|
|
29
|
+
- Sticky headers: `maxHeight` (any CSS length) lets the table scroll inside; the header stays at the top and the pinned rows stay under it, with a soft shadow while rows scroll beneath; `--su-table-sticky-shadow`
|
|
30
|
+
- Double-click editing: a double-click on an editable cell edits its row, starting in that field with its text selected; while a row is being edited, a double-click elsewhere never drops its changes. `editOnDoubleClick` turns it off. Without other actions, an actions column shows for Save and Cancel while a row is edited
|
|
31
|
+
- Theming: CSS variables for the header (font size and weight, letter spacing, text transform, padding, border), rows (background, text colour, stripes), the selected row's text, the sorted column, hovered editable cells, the caption, checkbox size, the move handle and a drop line showing where a dragged row will land (`--su-table-drop-line-color`, `--su-table-drop-line-width`)
|
|
32
|
+
- `rowClass` adds your own classes to rows; `is-muted` and `is-highlighted` come styled, with their own variables
|
|
33
|
+
- `columnsChange` emits every column's state (`SuTableColumnState`: shown, pinned) after a change in the Columns menu, e.g. to save it
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
- The cell that heads each row is a `<td role="rowheader">` instead of a `<th scope="row">`, styled through `.su-table-row-header` and `--su-table-row-header-weight`
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
- The table shrinks to fit inside grid and flex layouts, scrolling its columns instead of widening the page
|
|
40
|
+
|
|
41
|
+
## [22.0.0]
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
- `<su-lib-table>`: an accessible data table over typed columns (`SuTableColumns<TRow>`), with `caption`, `rowId`, `actions`, `selectable`, `reorderable` and `labels`
|
|
45
|
+
- Sorting from the column headings, with `aria-sort`
|
|
46
|
+
- Selection with checkboxes, and a toolbar to edit the selected rows together, run bulk actions or clear the selection
|
|
47
|
+
- Inline editing of one row (the `edit` action) and bulk editing of many, with validation messages; `edited` emits the saved rows in the API's shape
|
|
48
|
+
- Reordering by dragging the handle (mouse or touch; the row follows the pointer and the others slide aside to open its place) or with the keyboard; `reordered` emits the new order
|
|
49
|
+
- Row actions, hidden or disabled per row; `action` emits the clicked or selected rows
|
|
50
|
+
- `suTableCell` templates for custom cells
|
|
51
|
+
- Every change announced to screen readers, every text replaceable with `labels`
|
|
52
|
+
- Every part themeable with `--su-table-*` CSS variables
|
|
53
|
+
- Depends on exactly `@su-labs/core` 1.7.0 (version 22 follows Angular 22)
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yevheniy Alekseyev <yev.alekseyev@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,380 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Table
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@su-labs/table`
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
Accessible data tables for Angular, mapped from your API's JSON with typed columns: sort, select, edit one row or many
|
|
11
|
+
at once, reorder by dragging or with the keyboard, and act on rows with your own buttons. Edited rows come back in the
|
|
12
|
+
API's own shape, ready to send.
|
|
13
|
+
|
|
14
|
+
> **Not using Angular?** The same table logic is in [`@su-labs/core/table`](https://www.npmjs.com/package/@su-labs/core).
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- **Typed columns**: each column maps one field of your row type; its `format`, `sortable` and `edit` are typed by
|
|
19
|
+
that field, with no `any`
|
|
20
|
+
- **Sorting**: ascending, descending, then back to the rows' own order; numbers, dates and text compare naturally
|
|
21
|
+
- **Editing**: one row inline, or many selected rows at once (only the fields you change are applied to all of them),
|
|
22
|
+
with validation messages
|
|
23
|
+
- **Reordering**: drag the handle (mouse or touch), or with the keyboard: Space picks the row up, the arrows move it,
|
|
24
|
+
Space drops it, Escape puts it back
|
|
25
|
+
- **Row actions**: edit, delete, duplicate… any button, hidden or disabled per row, and bulk actions for the selection
|
|
26
|
+
- **Accessible**: a real `<table>` with a caption and row headers, sort buttons with `aria-sort`, labelled checkboxes
|
|
27
|
+
and handles, and every change announced to screen readers
|
|
28
|
+
- **Themeable**: every colour and spacing is a `--su-table-*` CSS variable
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npm install @su-labs/table
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Peer dependencies: `@angular/core` and `@angular/common` 22.
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
Describe your API's rows and map each field to a column:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { suCheckboxEditor, suNumberEditor, suSelectEditor, SuTableAction, SuTableActionEvent, SuTableColumns, SuTableComponent, SuTableReorderEvent, suTextEditor } from '@su-labs/table';
|
|
44
|
+
|
|
45
|
+
interface User {
|
|
46
|
+
readonly id: number;
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly age: number;
|
|
49
|
+
readonly admin: boolean;
|
|
50
|
+
readonly status: 'active' | 'paused';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Component({
|
|
54
|
+
selector: 'app-users',
|
|
55
|
+
imports: [SuTableComponent],
|
|
56
|
+
template: `
|
|
57
|
+
<su-lib-table
|
|
58
|
+
caption="Users"
|
|
59
|
+
selectable
|
|
60
|
+
reorderable
|
|
61
|
+
[columns]="columns"
|
|
62
|
+
[rows]="users()"
|
|
63
|
+
[rowId]="userId"
|
|
64
|
+
[actions]="actions"
|
|
65
|
+
(edited)="save($event)"
|
|
66
|
+
(reordered)="reorder($event)"
|
|
67
|
+
(action)="onAction($event)"
|
|
68
|
+
/>
|
|
69
|
+
`,
|
|
70
|
+
})
|
|
71
|
+
export class UsersPage {
|
|
72
|
+
protected readonly users = signal<readonly User[]>([]);
|
|
73
|
+
protected readonly userId = (user: User) => user.id;
|
|
74
|
+
|
|
75
|
+
protected readonly columns: SuTableColumns<User> = [
|
|
76
|
+
{ key: 'name', header: 'Name', sortable: true, edit: suTextEditor({ requiredMessage: 'Enter a name' }) },
|
|
77
|
+
{ key: 'age', header: 'Age', sortable: true, align: 'end', edit: suNumberEditor({ min: 0, max: 130 }) },
|
|
78
|
+
{ key: 'admin', header: 'Admin', edit: suCheckboxEditor() },
|
|
79
|
+
{
|
|
80
|
+
key: 'status',
|
|
81
|
+
header: 'Status',
|
|
82
|
+
sortable: true,
|
|
83
|
+
format: (status) => (status === 'active' ? 'Active' : 'Paused'),
|
|
84
|
+
edit: suSelectEditor([
|
|
85
|
+
{ value: 'active', label: 'Active' },
|
|
86
|
+
{ value: 'paused', label: 'Paused' },
|
|
87
|
+
]),
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
|
|
91
|
+
protected readonly actions: readonly SuTableAction<User>[] = [
|
|
92
|
+
{ id: 'edit', label: 'Edit' },
|
|
93
|
+
{ id: 'duplicate', label: 'Duplicate' },
|
|
94
|
+
{ id: 'delete', label: 'Delete', danger: true, bulk: true, disabled: (user) => user.admin },
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
protected save(rows: readonly User[]): void {
|
|
98
|
+
// PUT each row as it is; then update `users` with the API's answer
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
protected reorder({ rows }: SuTableReorderEvent<User>): void {
|
|
102
|
+
this.users.set(rows);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
protected onAction({ id, rows }: SuTableActionEvent<User>): void {
|
|
106
|
+
// 'duplicate' or 'delete' for these rows (confirm a delete with @su-labs/dialog)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The `edit` action is handled by the table: it edits that row inline (Enter saves, Escape cancels). A double-click on
|
|
112
|
+
an editable cell does the same, starting in that field (`editOnDoubleClick` turns it off); the Edit button stays as the
|
|
113
|
+
way in for keyboards. Selecting rows
|
|
114
|
+
shows a toolbar to edit them together or run the bulk actions.
|
|
115
|
+
|
|
116
|
+
### Custom cells
|
|
117
|
+
|
|
118
|
+
Put anything in a column's cells with a template; `suTableCellOf` only types the row:
|
|
119
|
+
|
|
120
|
+
```html
|
|
121
|
+
<su-lib-table caption="Users" [columns]="columns" [rows]="users()">
|
|
122
|
+
<ng-template suTableCell="status" [suTableCellOf]="users()" let-user let-text="text">
|
|
123
|
+
<span class="badge" [class.is-active]="user.status === 'active'">{{ text }}</span>
|
|
124
|
+
</ng-template>
|
|
125
|
+
</su-lib-table>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## API
|
|
129
|
+
|
|
130
|
+
### Inputs
|
|
131
|
+
|
|
132
|
+
| Input | Default | Description |
|
|
133
|
+
|-------|---------|-------------|
|
|
134
|
+
| `columns` | — | `SuTableColumns<TRow>`, one per field (see below) |
|
|
135
|
+
| `rows` | — | The rows, as the API sends them |
|
|
136
|
+
| `caption` | — | The table's name for screen readers |
|
|
137
|
+
| `showCaption` | `false` | Shows the caption on screen too |
|
|
138
|
+
| `rowId` | each row object | The row's identity, e.g. `(user) => user.id`; keeps the selection when new rows arrive |
|
|
139
|
+
| `actions` | `[]` | `SuTableAction<TRow>[]`, buttons on each row |
|
|
140
|
+
| `selectable` | `false` | Checkboxes to select rows, with a toolbar for the selection |
|
|
141
|
+
| `reorderable` | `false` | A move handle on each row |
|
|
142
|
+
| `columnControls` | `false` | A Columns button with a menu: search, Select all, a checkbox to show each column, and a toggle for the pin in its heading |
|
|
143
|
+
| `pageSize` | `'all'` | Rows per page |
|
|
144
|
+
| `pageSizes` | `[]` | Page sizes to choose from under the table, e.g. `[10, 25, 50, 'all']` |
|
|
145
|
+
| `maxHeight` | — | Any CSS length, e.g. `'28rem'`: the table scrolls inside, keeping the header and pinned rows in view |
|
|
146
|
+
| `editOnDoubleClick` | `true` | A double-click on an editable cell edits its row, starting in that field |
|
|
147
|
+
| `searchable` | `false` | A search box above the table that narrows the rows by their text |
|
|
148
|
+
| `rowPinning` | `false` | A Pin button on each row, keeping it above the others on every page |
|
|
149
|
+
| `pinnedRows` | — | The ids of the rows pinned to start with |
|
|
150
|
+
| `rowClass` | — | Extra classes for a row, e.g. `(row) => (row.active ? null : 'is-muted')` |
|
|
151
|
+
| `labels` | English | `Partial<SuTableLabels>`: any text, e.g. in the page's language |
|
|
152
|
+
|
|
153
|
+
### Outputs
|
|
154
|
+
|
|
155
|
+
| Output | Payload |
|
|
156
|
+
|--------|---------|
|
|
157
|
+
| `edited` | `readonly TRow[]`: the saved rows in the API's shape |
|
|
158
|
+
| `reordered` | `{ ids, rows }`: every row in its new order |
|
|
159
|
+
| `action` | `{ id, rows }`: the clicked row, or the selected rows for a bulk action |
|
|
160
|
+
| `sortChange` | `{ key, direction } \| null` |
|
|
161
|
+
| `selectionChange` | `readonly TRow[]` |
|
|
162
|
+
| `pageChange` | `{ page, pageSize }`, the page from 0 |
|
|
163
|
+
| `searchChange` | The query, once typing pauses |
|
|
164
|
+
| `columnsChange` | Every column's state (`{ key, header, visible, pinned }`) after a change in the Columns menu |
|
|
165
|
+
| `pinnedRowsChange` | The ids of the pinned rows, in pin order |
|
|
166
|
+
|
|
167
|
+
The table shows your changes right away; update `rows` with the API's answer to keep them, or to undo a failed save.
|
|
168
|
+
|
|
169
|
+
### Columns
|
|
170
|
+
|
|
171
|
+
| Field | Description |
|
|
172
|
+
|-------|-------------|
|
|
173
|
+
| `key` | The field in the row |
|
|
174
|
+
| `header` | The column's heading |
|
|
175
|
+
| `format(value, row)` | The cell's text; by default the value (booleans as Yes and No, nothing for null) |
|
|
176
|
+
| `sortable` | `true`, or how two values compare |
|
|
177
|
+
| `edit` | How the field is edited; without it the column is read-only |
|
|
178
|
+
| `validate(value, row)` | A message when an edited value isn't valid, or `null` |
|
|
179
|
+
| `align` | `'start'`, `'center'` or `'end'` |
|
|
180
|
+
| `pinned` | `'start'` or `'end'`: stays in view at that edge while the other columns scroll |
|
|
181
|
+
| `pinnable` | `true` to show the pin in its heading (default: only on pinned columns) |
|
|
182
|
+
| `searchable` | `false` to leave the column out of the search (default `true`) |
|
|
183
|
+
| `hidden` | `true` to start out of view; the field stays in the row data and comes back on save |
|
|
184
|
+
|
|
185
|
+
### Editors
|
|
186
|
+
|
|
187
|
+
| Editor | API value | Control |
|
|
188
|
+
|--------|-----------|---------|
|
|
189
|
+
| `suTextEditor({ input, requiredMessage, maxLength, placeholder })` | `string` (trimmed) | `text`, `email` or `textarea` |
|
|
190
|
+
| `suNumberEditor({ min, max, step, invalidMessage })` | `number` | `number` |
|
|
191
|
+
| `suCheckboxEditor()` | `boolean` | checkbox |
|
|
192
|
+
| `suDateEditor({ min, max })` | `string`, `YYYY-MM-DD` | date |
|
|
193
|
+
| `suSelectEditor([{ value, label }, …])` | one of the values | select |
|
|
194
|
+
|
|
195
|
+
Any other field gets its own `SuTableEditor<TValue>`: an `input`, `toInput(value)` for the control, `parse(input)`
|
|
196
|
+
back to the API value, and an optional `validate(value)`.
|
|
197
|
+
|
|
198
|
+
### Actions
|
|
199
|
+
|
|
200
|
+
| Field | Description |
|
|
201
|
+
|-------|-------------|
|
|
202
|
+
| `id` / `label` | `'edit'` edits the row inline; any other id is sent to `action` |
|
|
203
|
+
| `danger` | Styled as something that can't be undone |
|
|
204
|
+
| `bulk` | Also offered for the selected rows |
|
|
205
|
+
| `hidden(row)` / `disabled(row)` | Leaves the button out, or disables it, for a row |
|
|
206
|
+
|
|
207
|
+
## Pinned columns
|
|
208
|
+
|
|
209
|
+
Pin a column to keep it in view while the others scroll, e.g. the product name on a phone:
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
{ key: 'name', header: 'Product', pinned: 'start' },
|
|
213
|
+
{ key: 'price', header: 'Price', pinned: 'end' },
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Pinned columns move to their edge in the order you list them. The move handles and checkboxes stay with the columns
|
|
217
|
+
pinned to the start, and the actions with those pinned to the end. A soft shadow shows on the pinned edge while other
|
|
218
|
+
columns scroll under it. Pinned columns, and columns marked `pinnable: true`, show a pin in their heading: tapping it pins or
|
|
219
|
+
unpins the column. The Columns menu (`columnControls`) chooses which headings show that pin. If the
|
|
220
|
+
pinned columns would leave too little room for the rest, they stop sticking until there's room again.
|
|
221
|
+
|
|
222
|
+
## Sticky header
|
|
223
|
+
|
|
224
|
+
Give the table a `maxHeight` and it scrolls inside that height, keeping the header at the top and the pinned rows just
|
|
225
|
+
under it, with a soft shadow once rows scroll beneath them:
|
|
226
|
+
|
|
227
|
+
```html
|
|
228
|
+
<su-lib-table caption="Products" [columns]="columns" [rows]="products()" maxHeight="28rem" />
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Without a `maxHeight` the table grows with its rows and the page scrolls instead. A header can't stick to the page
|
|
232
|
+
itself while the table scrolls sideways, which it needs to do on narrow screens.
|
|
233
|
+
|
|
234
|
+
## Showing and hiding columns
|
|
235
|
+
|
|
236
|
+
Load all of the API's fields and show only some: `hidden: true` starts a column out of view, and with `columnControls`
|
|
237
|
+
the Columns menu has a checkbox for each column beside its pin choice. Hidden fields stay in each row, so a saved row
|
|
238
|
+
still comes back whole; they're left out of the search and the edit fields, and the last column on view can't be
|
|
239
|
+
hidden. Keep the layout with `columnsChange`.
|
|
240
|
+
|
|
241
|
+
## Search
|
|
242
|
+
|
|
243
|
+
`searchable` adds a search box above the table. It matches the text people see (so `€18.50` and `Garden` match, not
|
|
244
|
+
`18.5` and `garden`), ignores case and accents, and needs every word typed to match somewhere in the row. It runs once
|
|
245
|
+
typing pauses and announces how many rows match; Escape clears it. Pinned rows stay, the pages cover the matches, and
|
|
246
|
+
reordering is off while searching. Leave a column out with `searchable: false`.
|
|
247
|
+
|
|
248
|
+
## Pinned rows
|
|
249
|
+
|
|
250
|
+
With `rowPinning`, each row gets a Pin button. Pinned rows stay above the others on every page, in the order they were
|
|
251
|
+
pinned, and aren't counted in the pages or moved by sorting and reordering; unpinning puts a row back where it was.
|
|
252
|
+
Start with some pinned, and keep track of them, e.g. to save them:
|
|
253
|
+
|
|
254
|
+
```html
|
|
255
|
+
<su-lib-table … rowPinning [pinnedRows]="[103]" (pinnedRowsChange)="savePins($event)" />
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Pagination
|
|
259
|
+
|
|
260
|
+
```html
|
|
261
|
+
<su-lib-table caption="Products" [columns]="columns" [rows]="products()" [pageSize]="25" [pageSizes]="[10, 25, 50, 'all']" />
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Under the table: a rows-per-page choice, the range on screen ("26–50 of 132") and previous and next buttons; each page
|
|
265
|
+
change is announced. Changing the page size keeps the first row on screen in view, sorting goes back to the first page,
|
|
266
|
+
and the select-all checkbox selects the rows of the page on screen while the selection is kept across pages.
|
|
267
|
+
|
|
268
|
+
## Keyboard
|
|
269
|
+
|
|
270
|
+
| Where | Key | Does |
|
|
271
|
+
|-------|-----|------|
|
|
272
|
+
| Column heading | Enter or Space | Sorts by it: ascending, descending, then unsorted |
|
|
273
|
+
| Move handle | Space or Enter | Picks the row up, then drops it |
|
|
274
|
+
| Move handle, row picked up | ↑ / ↓, Home / End | Moves it one place, or to the top or bottom |
|
|
275
|
+
| Move handle, row picked up | Escape or Tab | Puts it back where it was |
|
|
276
|
+
| Row being edited | Enter / Escape | Saves / cancels |
|
|
277
|
+
|
|
278
|
+
## Styling
|
|
279
|
+
|
|
280
|
+
Every colour, border, size and state is a CSS variable. Set them on `:root` (your theme), on `su-lib-table`, or on a
|
|
281
|
+
class for one table:
|
|
282
|
+
|
|
283
|
+
```css
|
|
284
|
+
su-lib-table {
|
|
285
|
+
--su-table-header-background: #0f3d2e;
|
|
286
|
+
--su-table-header-color: #d1fae5;
|
|
287
|
+
--su-table-header-text-transform: uppercase;
|
|
288
|
+
--su-table-stripe-background: rgb(16 185 129 / 0.06);
|
|
289
|
+
--su-table-sorted-background: rgb(16 185 129 / 0.1);
|
|
290
|
+
--su-table-drop-line-color: #10b981;
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Row states
|
|
295
|
+
|
|
296
|
+
`rowClass` adds your own classes to a row, e.g. to mark inactive rows. The table styles two of them:
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
rowClass = (user: User) => (user.active ? null : 'is-muted');
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
| Class | Variables |
|
|
303
|
+
|-------|-----------|
|
|
304
|
+
| `is-muted` | `--su-table-muted-background` (`transparent`), `--su-table-muted-text` (`55%`, how much of the text colour shows) |
|
|
305
|
+
| `is-highlighted` | `--su-table-highlight-background` (a soft amber tint) |
|
|
306
|
+
|
|
307
|
+
Other classes are yours to style from a global stylesheet.
|
|
308
|
+
|
|
309
|
+
### Variables
|
|
310
|
+
|
|
311
|
+
Defaults are in brackets; "tint" means the accent blue at a low opacity.
|
|
312
|
+
|
|
313
|
+
**Table**
|
|
314
|
+
|
|
315
|
+
| Variable | Default |
|
|
316
|
+
|----------|---------|
|
|
317
|
+
| `--su-table-font-family` / `--su-table-font-size` / `--su-table-text-color` | `inherit` / `0.95rem` / `inherit` |
|
|
318
|
+
| `--su-table-background` | `transparent` |
|
|
319
|
+
| `--su-table-border` / `--su-table-radius` | `1px solid rgb(0 0 0 / 0.12)` / `10px` |
|
|
320
|
+
| `--su-table-cell-padding` / `--su-table-cell-vertical-align` | `0.6rem 0.75rem` / `middle` |
|
|
321
|
+
| `--su-table-caption-color` / `--su-table-caption-font-size` | `inherit` |
|
|
322
|
+
| `--su-table-accent` | `#2563eb` (checkboxes, pressed pins) |
|
|
323
|
+
| `--su-table-checkbox-size` | `1rem` |
|
|
324
|
+
| `--su-table-focus-outline` | `2px solid currentColor` |
|
|
325
|
+
|
|
326
|
+
**Header**
|
|
327
|
+
|
|
328
|
+
| Variable | Default |
|
|
329
|
+
|----------|---------|
|
|
330
|
+
| `--su-table-header-background` / `--su-table-header-color` | a faint grey / `inherit` |
|
|
331
|
+
| `--su-table-header-font-size` / `--su-table-header-font-weight` | `inherit` / `600` |
|
|
332
|
+
| `--su-table-header-text-transform` / `--su-table-header-letter-spacing` | `none` / `normal` |
|
|
333
|
+
| `--su-table-header-padding` / `--su-table-header-border` | the cell padding / the row border |
|
|
334
|
+
| `--su-table-sticky-shadow` | `0 6px 8px -6px rgb(0 0 0 / 0.25)` (under a sticky header while rows scroll beneath) |
|
|
335
|
+
|
|
336
|
+
**Rows and cells**
|
|
337
|
+
|
|
338
|
+
| Variable | Default |
|
|
339
|
+
|----------|---------|
|
|
340
|
+
| `--su-table-row-background` / `--su-table-row-color` | `transparent` / `inherit` |
|
|
341
|
+
| `--su-table-stripe-background` | the row background (set it for striped rows) |
|
|
342
|
+
| `--su-table-row-border` / `--su-table-row-header-weight` | `1px solid rgb(0 0 0 / 0.08)` / `600` |
|
|
343
|
+
| `--su-table-hover-background` | a faint grey |
|
|
344
|
+
| `--su-table-selected-background` / `--su-table-selected-color` | a tint / `inherit` |
|
|
345
|
+
| `--su-table-sorted-background` | `transparent` (the sorted column's cells and heading) |
|
|
346
|
+
| `--su-table-editable-hover-background` | the text colour at 6% (an editable cell under the pointer) |
|
|
347
|
+
| `--su-table-editing-background` | a tint (the row being edited) |
|
|
348
|
+
|
|
349
|
+
**Reordering**
|
|
350
|
+
|
|
351
|
+
| Variable | Default |
|
|
352
|
+
|----------|---------|
|
|
353
|
+
| `--su-table-handle-color` | `inherit` |
|
|
354
|
+
| `--su-table-grabbed-background` / `--su-table-grabbed-outline` | a tint / `2px solid` blue at 60% |
|
|
355
|
+
| `--su-table-dragging-background` / `--su-table-dragging-shadow` | `Canvas` / `0 8px 24px rgb(0 0 0 / 0.18)` |
|
|
356
|
+
| `--su-table-drop-line-color` / `--su-table-drop-line-width` | `#2563eb` / `2px` (where the dragged row will land) |
|
|
357
|
+
|
|
358
|
+
**Pinned columns and rows**
|
|
359
|
+
|
|
360
|
+
| Variable | Default |
|
|
361
|
+
|----------|---------|
|
|
362
|
+
| `--su-table-pinned-background` | `Canvas` (behind pinned and sticky cells) |
|
|
363
|
+
| `--su-table-pinned-border` / `--su-table-pinned-shadow` | `1px solid rgb(0 0 0 / 0.14)` / `rgb(0 0 0 / 0.22)` |
|
|
364
|
+
| `--su-table-pinned-row-background` / `--su-table-pinned-row-border` | a tint / `2px solid` blue at 40% |
|
|
365
|
+
|
|
366
|
+
**Buttons, inputs and panels**
|
|
367
|
+
|
|
368
|
+
| Variable | Default |
|
|
369
|
+
|----------|---------|
|
|
370
|
+
| `--su-table-button-background` / `--su-table-button-border` / `--su-table-button-color` | `transparent` / `1px solid rgb(0 0 0 / 0.2)` / `inherit` |
|
|
371
|
+
| `--su-table-button-radius` / `--su-table-button-padding` | `6px` / `0.3rem 0.7rem` |
|
|
372
|
+
| `--su-table-primary-background` / `--su-table-primary-color` | `#111` / `#fff` (Save) |
|
|
373
|
+
| `--su-table-danger-color` / `--su-table-danger-border` | `#b42318` / a soft red line |
|
|
374
|
+
| `--su-table-input-background` / `--su-table-input-border` / `--su-table-input-radius` | `transparent` / `1px solid rgb(0 0 0 / 0.25)` / `6px` |
|
|
375
|
+
| `--su-table-panel-background` | a faint grey (selection toolbar and bulk edit) |
|
|
376
|
+
| `--su-table-menu-background` / `--su-table-menu-shadow` | `Canvas` / `0 12px 32px rgb(0 0 0 / 0.18)` (the Columns menu) |
|
|
377
|
+
|
|
378
|
+
## Browser Compatibility
|
|
379
|
+
|
|
380
|
+
Uses pointer events and `color-mix()`: Chrome, Edge, Firefox and Safari from 2023 on.
|