vlite3 1.5.11 → 1.5.13
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/README.md +20 -8
- package/components/Accordion/AccordionContent.vue.js +2 -2
- package/components/CategoryManager/CategoryManager2.vue.js +1 -1
- package/components/CommandPalette/CommandPaletteContent2.vue.js +1 -1
- package/components/CommandPalette/{CommandPaletteItem2.vue.js → CommandPaletteItem.vue.js} +1 -1
- package/components/Dropdown/DropdownMenu.vue.js +1 -1
- package/components/Form/{AccordionView.vue.js → AccordionView2.vue.js} +2 -2
- package/components/Form/Form.vue.js +2 -2
- package/components/Form/index2.vue.js +1 -1
- package/components/NavbarCommandPalette.vue.js +1 -1
- package/components/PanZoomViewport/PanZoomViewport.vue.d.ts +7 -7
- package/components/PanZoomViewport/PanZoomViewport.vue.js +1 -1
- package/components/Screen/ScreenFilter.vue.js +1 -1
- package/components/Splitter/Splitter.vue.d.ts +7 -0
- package/components/Splitter/Splitter.vue.js +33 -29
- package/components/Tabes/Tabes.vue.js +2 -2
- package/docs/README.md +17 -0
- package/docs/all-components.md +89 -0
- package/docs/component-index.md +313 -0
- package/docs/components/accordion.md +52 -0
- package/docs/components/alert.md +34 -0
- package/docs/components/app-shell.md +371 -0
- package/docs/components/async-select.md +264 -0
- package/docs/components/attachments-list.md +231 -0
- package/docs/components/avatar-group.md +74 -0
- package/docs/components/avatar-uploader.md +61 -0
- package/docs/components/avatar.md +28 -0
- package/docs/components/badge.md +81 -0
- package/docs/components/barcode.md +42 -0
- package/docs/components/beacon.md +29 -0
- package/docs/components/breadcrumb.md +317 -0
- package/docs/components/button-group.md +35 -0
- package/docs/components/button.md +86 -0
- package/docs/components/calendar.md +95 -0
- package/docs/components/carousel.md +122 -0
- package/docs/components/cart.md +533 -0
- package/docs/components/category-manager.md +269 -0
- package/docs/components/category-menu.md +251 -0
- package/docs/components/charts.md +1456 -0
- package/docs/components/chat.md +330 -0
- package/docs/components/checkbox.md +31 -0
- package/docs/components/chip.md +137 -0
- package/docs/components/choice-box.md +40 -0
- package/docs/components/clipboard.md +105 -0
- package/docs/components/clock.md +70 -0
- package/docs/components/color-picker.md +82 -0
- package/docs/components/command-palette.md +214 -0
- package/docs/components/comment-thread.md +171 -0
- package/docs/components/confirmation-modal.md +50 -0
- package/docs/components/custom-fields-display.md +94 -0
- package/docs/components/custom-fields.md +97 -0
- package/docs/components/data-list.md +93 -0
- package/docs/components/data-table.md +922 -0
- package/docs/components/date-picker.md +58 -0
- package/docs/components/date-range-picker.md +24 -0
- package/docs/components/date-time.md +104 -0
- package/docs/components/dropdown.md +740 -0
- package/docs/components/empty.md +100 -0
- package/docs/components/export-data.md +320 -0
- package/docs/components/file-picker.md +83 -0
- package/docs/components/file-preview.md +42 -0
- package/docs/components/file-tree.md +144 -0
- package/docs/components/footer.md +251 -0
- package/docs/components/forms.md +776 -0
- package/docs/components/gantt-chart.md +767 -0
- package/docs/components/google-login.md +67 -0
- package/docs/components/google-map.md +128 -0
- package/docs/components/heatmap.md +80 -0
- package/docs/components/icon-picker.md +58 -0
- package/docs/components/icon.md +176 -0
- package/docs/components/image-comparison.md +51 -0
- package/docs/components/image-magnifier.md +26 -0
- package/docs/components/import-data.md +521 -0
- package/docs/components/input.md +58 -0
- package/docs/components/invoice.md +339 -0
- package/docs/components/kanban.md +302 -0
- package/docs/components/label.md +25 -0
- package/docs/components/list.md +419 -0
- package/docs/components/masonry.md +55 -0
- package/docs/components/modal.md +133 -0
- package/docs/components/multi-select.md +54 -0
- package/docs/components/navbar.md +403 -0
- package/docs/components/number-input.md +41 -0
- package/docs/components/otp-input.md +68 -0
- package/docs/components/pagination.md +83 -0
- package/docs/components/pan-zoom-viewport.md +245 -0
- package/docs/components/permission-editor.md +322 -0
- package/docs/components/persona.md +56 -0
- package/docs/components/price.md +106 -0
- package/docs/components/pricing-plan.md +68 -0
- package/docs/components/progress-bar.md +53 -0
- package/docs/components/qr-code.md +59 -0
- package/docs/components/rating.md +59 -0
- package/docs/components/rich-text-editor.md +210 -0
- package/docs/components/scale-generator.md +101 -0
- package/docs/components/screen.md +208 -0
- package/docs/components/seo-provider.md +189 -0
- package/docs/components/side-panel.md +94 -0
- package/docs/components/sidebar-menu.md +422 -0
- package/docs/components/skeleton.md +115 -0
- package/docs/components/slider.md +48 -0
- package/docs/components/spinner.md +27 -0
- package/docs/components/splitter.md +97 -0
- package/docs/components/stats.md +234 -0
- package/docs/components/status-chip.md +232 -0
- package/docs/components/switch.md +23 -0
- package/docs/components/tabs.md +335 -0
- package/docs/components/tag-input.md +55 -0
- package/docs/components/textarea.md +31 -0
- package/docs/components/theme-provider.md +130 -0
- package/docs/components/theme-toggle.md +36 -0
- package/docs/components/thumbnail-selector.md +186 -0
- package/docs/components/timeline.md +225 -0
- package/docs/components/toast-notification.md +89 -0
- package/docs/components/tooltip.md +31 -0
- package/docs/components/workbook.md +102 -0
- package/docs/composables/use-theme.md +59 -0
- package/docs/getting-started/setup.md +176 -0
- package/docs/guides/draggable.md +211 -0
- package/docs/guides/internationalization.md +281 -0
- package/docs/guides/performance.md +118 -0
- package/docs/guides/testing-forms.md +154 -0
- package/docs/guides/testing-overlays.md +131 -0
- package/docs/guides/theming.md +124 -0
- package/docs/utilities/search.md +580 -0
- package/docs/utilities/utilities.md +371 -0
- package/docs-manifest.json +339 -0
- package/package.json +6 -15
- package/scripts/generate-docs-manifest.js +207 -0
- package/scripts/sync-docs.js +754 -0
- package/style.css +1 -1
- /package/components/Dropdown/{DropdownMenu2.vue.js → DropdownMenu3.vue.js} +0 -0
|
@@ -0,0 +1,922 @@
|
|
|
1
|
+
# DataTable
|
|
2
|
+
|
|
3
|
+
**Import:** `import { DataTable } from 'vlite3'`
|
|
4
|
+
|
|
5
|
+
**Types:** `import type { TableHeader, DataTableProps, TableState, TableFilter, SelectionState, RowClickPayload, ExpandPayload, PageInfo, DataTablePaginationProps } from 'vlite3'`
|
|
6
|
+
|
|
7
|
+
A data table with sorting, pagination, row selection, hierarchical tree rows (static or async), loading skeletons, empty states, and Screen integration. Column cells support built-in types (`price`, `date`, `number`), custom formatters, status coloring, and named slots.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
### Props
|
|
12
|
+
|
|
13
|
+
| Prop | Type | Default | Description |
|
|
14
|
+
| :--------------------- | :------------------------- | :------------------ | :---------- |
|
|
15
|
+
| `rows` | `any[]` | `[]` | Data array to display. |
|
|
16
|
+
| `headers` | `TableHeader[]` | `[]` | Column definitions. See **TableHeader** below. |
|
|
17
|
+
| `keyField` | `string` | `'auto'` | Unique row identifier. Supports dot-notation. `'auto'` picks the first of `id` / `_id` found on the first row, otherwise falls back to `'_id'`. |
|
|
18
|
+
| `selectedRows` | `any[]` | `[]` | Selected rows (`v-model:selectedRows`). Survives across page changes when the parent keeps the array. |
|
|
19
|
+
| `loading` | `boolean` | `false` | Show loading skeleton rows (up to `itemsPerPage`, capped at 15). |
|
|
20
|
+
| `hideSelectable` | `boolean` | `false` | Hide the selection checkbox column. Always respected, including inside `Screen`. |
|
|
21
|
+
| `isRowSelectable` | `(row) => boolean` | — | Keep selection visible but disable it for rows where the predicate returns `false`. Header select-all and selection events exclude disabled rows. |
|
|
22
|
+
| `sortable` | `boolean` | `false` | Enable column sorting for headers that allow it (see **Sorting**). |
|
|
23
|
+
| `showPagination` | `boolean` | `true` | Show footer pagination when `pageInfo.totalPages > 1`. |
|
|
24
|
+
| `paginationProps` | `DataTablePaginationProps` | See below | Props forwarded to `Pagination` (excludes `currentPage` / `totalPages`). |
|
|
25
|
+
| `pageInfo` | `PageInfo` | — | Pagination metadata from the server. Required for the footer to render. |
|
|
26
|
+
| `striped` | `boolean` | `false` | Zebra striping on odd rows. |
|
|
27
|
+
| `hoverable` | `boolean` | `true` | Highlight row on hover. |
|
|
28
|
+
| `bordered` | `boolean` | `true` | Outer border on the table container. |
|
|
29
|
+
| `cellBordered` | `boolean` | `false` | Internal grid borders around every cell (vertical + horizontal). Pairs with `bordered` for the outer frame. |
|
|
30
|
+
| `rounded` | `boolean` | `true` | Rounded container corners. Set `false` for sharp/square edges (`rounded-none`). Also disables raised-variant header corner rounding. |
|
|
31
|
+
| `compact` | `boolean` | `false` | Reduced row/header padding (same as `size="xs"`). |
|
|
32
|
+
| `size` | `'xs' \| 'sm' \| 'md' \| 'lg'` | `'md'` | Row and header padding / text density. |
|
|
33
|
+
| `variant` | `'default' \| 'raised'` | `'default'` | Container style. `raised` adds shadow, padding, and rounded header corners (when `rounded` is `true`). |
|
|
34
|
+
| `headerVariant` | `'default' \| 'minimal'` | `'default'` | Header background. `default` uses `bg-accent`; `minimal` is transparent. |
|
|
35
|
+
| `tableClass` | `string` | — | Extra classes on the `<table>` element. |
|
|
36
|
+
| `class` | `string` | — | Extra classes on the outer container. |
|
|
37
|
+
| `emptyTitle` | `string` | — | Empty-state title. When omitted, `Empty` uses its own default (`No data found`). |
|
|
38
|
+
| `emptyTitleI18n` | `string` | — | i18n key for empty title (takes priority over `emptyTitle`). |
|
|
39
|
+
| `emptyDescription` | `string` | — | Empty-state description. |
|
|
40
|
+
| `emptyDescriptionI18n` | `string` | — | i18n key for empty description. |
|
|
41
|
+
| `emptyIcon` | `string` | `'lucide:inbox'` | Empty-state icon (Iconify id). |
|
|
42
|
+
| `loadChildren` | `(row) => Promise<any[]>` | — | Async loader for nested rows. Result is cached inside the table. |
|
|
43
|
+
| `treeIndent` | `number` | `20` | Horizontal indent (px) per tree depth on the first data column. |
|
|
44
|
+
| `responsive` | `boolean` | `true` | When `true`, viewports below the Tailwind `md` breakpoint (768px) render stacked labeled cards instead of the multi-column table. Set `false` to keep the always-table + horizontal-scroll layout. |
|
|
45
|
+
| `resizable` | `boolean` | `false` | Opt in to drag-to-resize column boundaries on the desktop table. See **Column resizing**. When `false` the table renders and behaves exactly as it does without the feature. |
|
|
46
|
+
| `persistenceKey` | `string` | — | Stable key used to persist user column widths in local storage. Separate from `keyField` (which identifies rows). Omit to keep resizing session-only. |
|
|
47
|
+
|
|
48
|
+
#### Responsive stacked cards
|
|
49
|
+
|
|
50
|
+
When `responsive` is enabled (default) and the viewport is below `md`:
|
|
51
|
+
|
|
52
|
+
- Each row becomes a bordered card.
|
|
53
|
+
- **Header:** checkbox / tree expand + the first visible non-action column (identity slot — e.g. avatar + name).
|
|
54
|
+
- **Body:** remaining visible columns as horizontal `LABEL | value` rows (label left, value right).
|
|
55
|
+
- **Footer:** columns whose `field` is `action` or `actions`, right-aligned.
|
|
56
|
+
- Selected cards use a `border-primary` outline with a soft `bg-muted` wash (no select-all bar on small screens).
|
|
57
|
+
- Columns with `hideOnMobile: true` stay hidden.
|
|
58
|
+
- Tree connector lines are desktop-only; expand/collapse and depth indent still work on cards.
|
|
59
|
+
|
|
60
|
+
At `md` and above, the original table is unchanged. No schema changes are required — layout is automatic from `headers`.
|
|
61
|
+
|
|
62
|
+
#### Default `paginationProps`
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
{
|
|
66
|
+
alignment: 'between',
|
|
67
|
+
navType: 'icon',
|
|
68
|
+
showItemsPerPage: true,
|
|
69
|
+
itemsPerPageOptions: [10, 25, 50, 100],
|
|
70
|
+
showPageInfo: false,
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### Events
|
|
77
|
+
|
|
78
|
+
| Event | Payload | Description |
|
|
79
|
+
| :--------------------- | :---------------- | :---------- |
|
|
80
|
+
| `@change` | `TableState` | Emitted (debounced ~10ms) on sort or pagination change. Also forwarded to `Screen` via context when nested. |
|
|
81
|
+
| `@select` | `SelectionState` | Emitted when row selection changes. |
|
|
82
|
+
| `@rowClick` | `RowClickPayload` | Emitted when a row is clicked (checkbox clicks do not trigger this). |
|
|
83
|
+
| `@delete` | `any[]` | Emitted with the selected rows after the internal delete confirmation is confirmed. Bulk delete in `Screen` is handled by Screen itself — prefer Screen’s `@delete` when using that layout. |
|
|
84
|
+
| `@update:selectedRows` | `any[]` | `v-model:selectedRows` binding. |
|
|
85
|
+
| `@update:itemsPerPage` | `number` | Emitted when the items-per-page selector changes. |
|
|
86
|
+
| `@expand` | `ExpandPayload` | Emitted when a tree row is expanded or collapsed. |
|
|
87
|
+
| `@columnResize` | `ColumnResizePayload` | Emitted when a column resize is committed (drag end, keyboard adjust, or double-click reset). Deliberately **not** folded into `@change`, which stays sorting + pagination only. |
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
### Column resizing
|
|
92
|
+
|
|
93
|
+
Off by default. Set `resizable` to let users drag column boundaries, the same
|
|
94
|
+
interaction model as [`Splitter`](./splitter.md) but scoped to table headers.
|
|
95
|
+
|
|
96
|
+
```vue
|
|
97
|
+
<DataTable
|
|
98
|
+
:headers="headers"
|
|
99
|
+
:rows="rows"
|
|
100
|
+
resizable
|
|
101
|
+
persistence-key="employees-table"
|
|
102
|
+
/>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
Column 1 | Column 2 | Column 3 | Column 4
|
|
107
|
+
↑ ↑ ↑ ↑ outer edge (when resizable)
|
|
108
|
+
Column 1 Column 2 Column 3 Column 4
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
- Each resizable column owns **one** boundary control on its logical trailing edge —
|
|
112
|
+
right in LTR, left in RTL. The divider between two columns always resizes the column
|
|
113
|
+
immediately before it; the next column is never selected by an index offset. A
|
|
114
|
+
resizable final column gets a control on its outer trailing edge.
|
|
115
|
+
- Without internal cell borders, the separator is rendered inside its owning `<th>`.
|
|
116
|
+
With `cellBordered`, the same owning edge is promoted to one measured, full-table-height
|
|
117
|
+
control so the visible grid boundary remains interactive through every body row. Both
|
|
118
|
+
variants pass `header.field` directly; neither uses a boundary index or neighbour lookup.
|
|
119
|
+
- The owning `header.field` is the single identity used by the handle, active state,
|
|
120
|
+
width update, persisted value and `@columnResize` payload.
|
|
121
|
+
- The line uses the owning header's rendered logical trailing edge. During a drag, the
|
|
122
|
+
owning `<col>` and the active control move in the same animation frame, so the accent
|
|
123
|
+
remains aligned with the actual boundary.
|
|
124
|
+
- The hit area is a generous invisible strip centred on the boundary; only the 2px line
|
|
125
|
+
is visible. While resizing is enabled, VLite's internal header-content box reserves a
|
|
126
|
+
`0.5rem` logical gap on both sides. This protects the owning header and the header after
|
|
127
|
+
the boundary even when a consumer applies dense or custom padding directly to `<th>`.
|
|
128
|
+
- Works with both the `default` and `minimal` header variants, and stays legible in
|
|
129
|
+
light and dark themes.
|
|
130
|
+
- Dragging continues outside the header and the table container. Only a clean pointer
|
|
131
|
+
release commits: `Escape`, `pointercancel` / `touchcancel`, lost pointer capture, the
|
|
132
|
+
table switching to stacked cards, and unmounting all restore the starting width
|
|
133
|
+
instead. The global cursor and text-selection lock are always released.
|
|
134
|
+
- Mouse, trackpad, touch and pen are supported through Pointer Events.
|
|
135
|
+
- Sorting is untouched: clicking the header content sorts as before, and interacting
|
|
136
|
+
with the boundary only resizes. Resizing never triggers row clicks, selection
|
|
137
|
+
changes, expand/collapse, or `@change`.
|
|
138
|
+
- The built-in selection checkbox column is fixed at 40px and is never resizable.
|
|
139
|
+
|
|
140
|
+
#### Visual states
|
|
141
|
+
|
|
142
|
+
| State | Appearance |
|
|
143
|
+
| :---- | :--------- |
|
|
144
|
+
| Rest | No resize accent; a bordered table keeps only its normal 1px grid line. |
|
|
145
|
+
| Hovering the boundary | A high-contrast 2px gray-700 accent appears on the owning column's trailing edge with the resize cursor. In a bordered table this applies anywhere along the visible vertical grid line. |
|
|
146
|
+
| Dragging | The owning column edge is accented and moves with the resized `<col>`. |
|
|
147
|
+
| Pointer release | The line disappears immediately. |
|
|
148
|
+
| Keyboard focus | The same edge is accented through `:focus-visible`. |
|
|
149
|
+
|
|
150
|
+
With `cellBordered`, the hit strip spans the rendered table height and the 2px accent
|
|
151
|
+
stays centred on the existing 1px cell border. The normal grid line remains untouched at rest; hover,
|
|
152
|
+
focus and active drag accent that same geometry rather than drawing a second offset line.
|
|
153
|
+
The layer contains one control per resizable column, not one per cell, and it isolates
|
|
154
|
+
pointer events from sorting, row clicks, selection, actions, tree expansion and text
|
|
155
|
+
selection. Columns with `resizable: false` render no separator.
|
|
156
|
+
|
|
157
|
+
#### Per-column opt-out
|
|
158
|
+
|
|
159
|
+
Set `resizable: false` on a header to pin it while the rest of the table resizes —
|
|
160
|
+
useful for action, icon and other fixed-width columns.
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const headers: TableHeader[] = [
|
|
164
|
+
{ field: 'employee', title: 'Employee', sortable: true },
|
|
165
|
+
{ field: 'email', title: 'Email', width: '260px' },
|
|
166
|
+
{ field: 'actions', title: '', width: '96px', align: 'center', resizable: false },
|
|
167
|
+
]
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### Width precedence
|
|
171
|
+
|
|
172
|
+
When the first resize begins, the table captures the widths that are actually rendered
|
|
173
|
+
on screen. Those already reflect configured pixel, percentage, Tailwind and natural
|
|
174
|
+
content sizing. After that point the effective width is:
|
|
175
|
+
|
|
176
|
+
1. A valid persisted or current user-resized width
|
|
177
|
+
2. The captured rendered width
|
|
178
|
+
3. A configured pixel `width` / `minWidth` only when a rendered measurement is not yet available
|
|
179
|
+
|
|
180
|
+
Percentage widths (`'22%'`) and Tailwind utilities (`'w-32'`) keep working. When a drag
|
|
181
|
+
starts on such a column its rendered width is captured and the resize continues in stable
|
|
182
|
+
pixels. Reset removes only the user override and restores that captured baseline.
|
|
183
|
+
|
|
184
|
+
Columns never shrink below `minWidth` (or 60px when no `minWidth` is set). At runtime,
|
|
185
|
+
the table also measures the header label, logical padding, sort control and other header
|
|
186
|
+
actions, and uses the largest of those floors. Body content remains single-line and
|
|
187
|
+
truncates within the resolved width instead of breaking words into fragments.
|
|
188
|
+
|
|
189
|
+
A column pinned with `resizable: false` always uses its developer-configured width. A
|
|
190
|
+
stale override saved while it was still resizable is ignored and dropped from storage,
|
|
191
|
+
so a fixed column can never end up with a width the user has no way to reset.
|
|
192
|
+
|
|
193
|
+
The consumer's `headers` array and header objects are never mutated.
|
|
194
|
+
|
|
195
|
+
#### Independent column sizing
|
|
196
|
+
|
|
197
|
+
User-owned widths remain independent, with one deliberate trailing-layout rule:
|
|
198
|
+
|
|
199
|
+
- Dragging a divider changes only the column immediately before it. Explicit widths of
|
|
200
|
+
neighbouring data, status and selection columns remain unchanged.
|
|
201
|
+
- If the final rendered column is fixed with `resizable: false`, positive unused viewport
|
|
202
|
+
space is added only to that final column. Its logical trailing edge stays pinned to the
|
|
203
|
+
viewport while its leading edge grows toward the table start. This passive fill is not
|
|
204
|
+
persisted as a user width.
|
|
205
|
+
- When that sum exceeds the viewport, the existing `overflow-x-auto` wrapper scrolls
|
|
206
|
+
horizontally; the trailing fill becomes zero and no required width is reduced.
|
|
207
|
+
- A resizable final column does not receive passive fill, so its outer trailing-edge
|
|
208
|
+
handle retains normal resize behaviour.
|
|
209
|
+
|
|
210
|
+
#### Resetting a column
|
|
211
|
+
|
|
212
|
+
**Double-click a resize boundary** (or press `Enter` / `Space` with it focused) to
|
|
213
|
+
restore that column's configured `width` / `minWidth` / natural width. The override is
|
|
214
|
+
removed from local storage, and every other resized column keeps its width.
|
|
215
|
+
|
|
216
|
+
#### Persistent column widths
|
|
217
|
+
|
|
218
|
+
With both `resizable` and `persistenceKey`, widths are saved through the shared
|
|
219
|
+
`usePersistentState` utility (so the usual `builto-` storage prefix applies):
|
|
220
|
+
|
|
221
|
+
```text
|
|
222
|
+
data-table:{persistenceKey}:column-widths
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Widths are keyed by stable `header.field` values — never by column index — so
|
|
226
|
+
reordering, hiding, adding or removing columns cannot shift them onto the wrong column.
|
|
227
|
+
The stored payload is versioned:
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
{
|
|
231
|
+
version: 1,
|
|
232
|
+
widths: { employee: 240, email: 300, status: 140 }
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The UI updates continuously while dragging; local storage is written **once, when the
|
|
237
|
+
resize finishes** (keyboard adjustments are debounced), never on every pointer move.
|
|
238
|
+
|
|
239
|
+
Behaviour:
|
|
240
|
+
|
|
241
|
+
- Sorting, pagination, refetching, loading states and row changes never reset widths.
|
|
242
|
+
- Reordering headers preserves widths by `field`.
|
|
243
|
+
- Newly added columns use their configured or natural width; removed columns are a no-op.
|
|
244
|
+
- Unknown or stale stored fields are ignored, as are invalid, negative, non-numeric or
|
|
245
|
+
corrupted values and payloads from a different schema version.
|
|
246
|
+
- Persisted widths still respect the column's current `minWidth`.
|
|
247
|
+
- Changing `persistenceKey` loads the state for the new table; two tables with different
|
|
248
|
+
keys stay completely independent.
|
|
249
|
+
- If storage is unavailable, blocked, corrupted or over quota, the table keeps working
|
|
250
|
+
without persistence.
|
|
251
|
+
- Without a `persistenceKey`, resizing still works for the session and **no** shared or
|
|
252
|
+
generic local-storage entry is created.
|
|
253
|
+
|
|
254
|
+
#### Responsive and tree behaviour
|
|
255
|
+
|
|
256
|
+
Resizing is a desktop-table affordance. In responsive stacked-card mode there are no
|
|
257
|
+
handles, desktop widths are not applied to cards, and stored widths do not affect
|
|
258
|
+
label/value positioning — they are preserved and restored when the desktop table
|
|
259
|
+
returns. With `responsive="false"` the normal table (and resizing) stays available on
|
|
260
|
+
small viewports through horizontal scroll.
|
|
261
|
+
|
|
262
|
+
Tree tables resize normally. The effective width is applied to the `<colgroup>`, the
|
|
263
|
+
header cell and the body column together, so indentation, connector lines, expand
|
|
264
|
+
controls, async child loading and the fixed selection column all stay aligned.
|
|
265
|
+
Expanding or collapsing rows never recalculates saved widths.
|
|
266
|
+
|
|
267
|
+
#### Accessibility
|
|
268
|
+
|
|
269
|
+
Each handle is an accessible separator:
|
|
270
|
+
|
|
271
|
+
| Aspect | Behaviour |
|
|
272
|
+
| :----- | :-------- |
|
|
273
|
+
| Role | `role="separator"` with `aria-orientation="vertical"` — the divider is a vertical line between columns |
|
|
274
|
+
| Value | `aria-valuenow` / `aria-valuetext` (current px), `aria-valuemin` (effective minimum), `aria-valuemax` |
|
|
275
|
+
| Label | `aria-label` from the column title (i18n key `vlite.dataTable.resizeColumn`) |
|
|
276
|
+
| Keyboard | `←` / `→` adjust by 8px, with `Shift` by 40px |
|
|
277
|
+
| Reset | `Enter` / `Space`, or double-click |
|
|
278
|
+
| Focus | `:focus-visible` only, so a pointer press never leaves the divider stuck on while keyboard users still get a clear indicator |
|
|
279
|
+
| RTL | Arrow keys follow the logical direction, so a handle always grows its own column |
|
|
280
|
+
|
|
281
|
+
Keyboard resizing honours the same minimums and persistence rules as pointer resizing.
|
|
282
|
+
Its storage write is debounced, and any queued write is flushed before a newer
|
|
283
|
+
interaction (a drag, a reset, another column) takes over, so a delayed commit can never
|
|
284
|
+
land after a later action.
|
|
285
|
+
|
|
286
|
+
#### `@columnResize` payload — `ColumnResizePayload`
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
{
|
|
290
|
+
field: string // header.field immediately before the divider
|
|
291
|
+
width: number | null // committed px width, null after a reset
|
|
292
|
+
previousWidth: number | null // width before this interaction
|
|
293
|
+
source: 'pointer' | 'keyboard' | 'reset'
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### Performance
|
|
298
|
+
|
|
299
|
+
Widths live in the table's `<colgroup>`, so a resize never touches body cells.
|
|
300
|
+
|
|
301
|
+
Everything scales with the number of **columns**, never rows. Each resizable header owns
|
|
302
|
+
one separator. In a bordered table that separator is a full-height overlay control
|
|
303
|
+
measured from the rendered header edge; no resize affordance or listener is rendered
|
|
304
|
+
inside body rows.
|
|
305
|
+
|
|
306
|
+
The drag path bypasses reactive width updates. Pointer movement is coalesced into
|
|
307
|
+
`requestAnimationFrame`, and each frame writes only the owning column's `<col>`, the
|
|
308
|
+
table width and (for `cellBordered`) the active boundary position. Other boundary
|
|
309
|
+
controls are disabled during the drag. No neighbouring data `<col>` is touched and row
|
|
310
|
+
data is not recalculated mid-drag. Reactive state and local storage are committed once,
|
|
311
|
+
when the interaction finishes. Global listeners and pending frames are always cleaned up.
|
|
312
|
+
|
|
313
|
+
#### Complete example
|
|
314
|
+
|
|
315
|
+
```vue
|
|
316
|
+
<script setup lang="ts">
|
|
317
|
+
import { ref, computed, onMounted } from 'vue'
|
|
318
|
+
import { DataTable } from 'vlite3'
|
|
319
|
+
import type { TableHeader, TableState, ColumnResizePayload } from 'vlite3'
|
|
320
|
+
|
|
321
|
+
const showSalary = ref(true)
|
|
322
|
+
|
|
323
|
+
// Headers may come from a computed, change after an API response, or be
|
|
324
|
+
// reordered — widths follow `field`, so they stay on the right column.
|
|
325
|
+
const headers = computed<TableHeader[]>(() => [
|
|
326
|
+
{ field: 'employee', title: 'Employee', sortable: true, minWidth: '200px' },
|
|
327
|
+
{ field: 'email', title: 'Email', sortable: true, width: '22%' },
|
|
328
|
+
...(showSalary.value
|
|
329
|
+
? [{ field: 'salary', title: 'Salary', type: 'price', align: 'right' } as TableHeader]
|
|
330
|
+
: []),
|
|
331
|
+
{ field: 'status', title: 'Status', capitalize: true, addStatusColor: true },
|
|
332
|
+
// Fixed utility column — pinned while everything else resizes.
|
|
333
|
+
{ field: 'actions', title: '', width: '96px', align: 'center', resizable: false },
|
|
334
|
+
])
|
|
335
|
+
|
|
336
|
+
const rows = ref([])
|
|
337
|
+
const loading = ref(false)
|
|
338
|
+
const pageInfo = ref()
|
|
339
|
+
|
|
340
|
+
const fetchData = async (state?: TableState) => {
|
|
341
|
+
loading.value = true
|
|
342
|
+
const res = await myApi.getEmployees(state)
|
|
343
|
+
rows.value = res.items
|
|
344
|
+
pageInfo.value = res.pageInfo
|
|
345
|
+
loading.value = false
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
onMounted(() => fetchData())
|
|
349
|
+
|
|
350
|
+
const onColumnResize = ({ field, width, source }: ColumnResizePayload) => {
|
|
351
|
+
console.log(`${field} → ${width ?? 'reset'} (${source})`)
|
|
352
|
+
}
|
|
353
|
+
</script>
|
|
354
|
+
|
|
355
|
+
<template>
|
|
356
|
+
<DataTable
|
|
357
|
+
:headers="headers"
|
|
358
|
+
:rows="rows"
|
|
359
|
+
:loading="loading"
|
|
360
|
+
:page-info="pageInfo"
|
|
361
|
+
sortable
|
|
362
|
+
resizable
|
|
363
|
+
persistence-key="employees-table"
|
|
364
|
+
@change="fetchData"
|
|
365
|
+
@column-resize="onColumnResize">
|
|
366
|
+
<template #actions="{ row }">
|
|
367
|
+
<Button variant="ghost" size="sm" icon="lucide:pencil" @click.stop="edit(row)" />
|
|
368
|
+
</template>
|
|
369
|
+
</DataTable>
|
|
370
|
+
</template>
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
### Tree view
|
|
376
|
+
|
|
377
|
+
Tree mode turns on automatically when any row has nested `children`, any row has `hasChildren: true`, or `loadChildren` is provided. Expansion state, loading spinner, children cache, indentation, connector lines, and chevrons are managed inside `DataTable`. Consumers only pass nested data (and optionally `loadChildren` / `treeIndent`) — no custom flatten or connector logic in the page.
|
|
378
|
+
|
|
379
|
+
The first data column hosts the tree chrome (connectors + expand control). In tree mode the table uses `table-layout: fixed` and a `<colgroup>` so expanding or collapsing nested rows does **not** recalculate column widths. Prefer setting `width` (or `minWidth`) on headers for stable columns; tree indent stays inside the first column only.
|
|
380
|
+
|
|
381
|
+
#### Row conventions (fixed field names)
|
|
382
|
+
|
|
383
|
+
| Field | Type | Purpose |
|
|
384
|
+
| :---- | :--- | :------ |
|
|
385
|
+
| `children` | `any[]` | Static / preloaded nested rows. |
|
|
386
|
+
| `hasChildren` | `boolean` | Async marker — show expand chevron when children are not loaded yet. |
|
|
387
|
+
|
|
388
|
+
Field names are fixed conventions on each row object (not configurable props).
|
|
389
|
+
|
|
390
|
+
```ts
|
|
391
|
+
// Static
|
|
392
|
+
{ id: 1, name: 'Phase', children: [{ id: 2, name: 'Task' }] }
|
|
393
|
+
|
|
394
|
+
// Async-ready
|
|
395
|
+
{ id: 1, name: 'Phase', hasChildren: true }
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
A row is expandable when it already has `children.length > 0`, or when `hasChildren === true` (until an async load resolves to an empty list, which then hides the chevron).
|
|
399
|
+
|
|
400
|
+
#### Connector lines
|
|
401
|
+
|
|
402
|
+
Hierarchy connectors use the shared **`TreeConnectors`** primitive (`src/components/TreeConnectors`, also used by [`FileTree`](../advanced/file-tree.md)). Geometry comes from `buildTreeConnectorSegments` — vertical trunks, horizontal branches, and final-child corners (`├` / `└`) are derived from each visible row’s `depth`, `isLastSibling`, and `ancestorLastFlags`, plus layout units (`treeIndent`, toggle size). Nothing is hard-coded to sample data or fixed row heights.
|
|
403
|
+
|
|
404
|
+
In `DataTable`, the connector overlay is absolutely positioned over the first cell (including vertical padding) with `bleed-y` so trunks stay continuous across row borders. Lines stop at the final child of a parent. Recalculation is automatic on expand/collapse, insert/remove, and re-render.
|
|
405
|
+
|
|
406
|
+
#### `@expand` payload — `ExpandPayload`
|
|
407
|
+
|
|
408
|
+
```ts
|
|
409
|
+
{
|
|
410
|
+
row: any
|
|
411
|
+
expanded: boolean
|
|
412
|
+
children?: any[] // static or freshly loaded children when expanding
|
|
413
|
+
depth: number
|
|
414
|
+
}
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
#### Selection in tree mode
|
|
418
|
+
|
|
419
|
+
Selecting a parent cascades to all **loaded** descendants. Deselecting a child updates ancestors (unchecked / indeterminate). Flat tables keep independent per-row selection.
|
|
420
|
+
|
|
421
|
+
#### Static tree
|
|
422
|
+
|
|
423
|
+
```vue
|
|
424
|
+
<DataTable
|
|
425
|
+
:rows="treeRows"
|
|
426
|
+
:headers="headers"
|
|
427
|
+
:tree-indent="20"
|
|
428
|
+
key-field="id"
|
|
429
|
+
@expand="({ row, expanded }) => console.log(row, expanded)"
|
|
430
|
+
/>
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
#### Async tree
|
|
434
|
+
|
|
435
|
+
```vue
|
|
436
|
+
<script setup lang="ts">
|
|
437
|
+
const roots = ref([
|
|
438
|
+
{ id: 1, name: 'Construction Phase', hasChildren: true },
|
|
439
|
+
])
|
|
440
|
+
|
|
441
|
+
const loadChildren = async (row: any) => {
|
|
442
|
+
const res = await api.getChildren(row.id)
|
|
443
|
+
return res.items // cached by DataTable — do not remap rows
|
|
444
|
+
}
|
|
445
|
+
</script>
|
|
446
|
+
|
|
447
|
+
<template>
|
|
448
|
+
<DataTable
|
|
449
|
+
:rows="roots"
|
|
450
|
+
:headers="headers"
|
|
451
|
+
:load-children="loadChildren"
|
|
452
|
+
key-field="id"
|
|
453
|
+
@expand="onExpand"
|
|
454
|
+
/>
|
|
455
|
+
</template>
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
### `@change` Payload — `TableState`
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
{
|
|
464
|
+
pagination: { page: number; limit: number }
|
|
465
|
+
sort: { field: string; order: 'asc' | 'desc' | '' }
|
|
466
|
+
filter: Record<string, any> // currently always `{}` from DataTable; reserved for consumers / Screen
|
|
467
|
+
}
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
> `sort.field` is the resolved `sortKey` when set on the header, otherwise the column `field`. That is the value sent to the backend.
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
### Sorting
|
|
475
|
+
|
|
476
|
+
Sorting requires the table-level `sortable` prop.
|
|
477
|
+
|
|
478
|
+
A column is sortable when **all** of the following are true:
|
|
479
|
+
|
|
480
|
+
1. `sortable` is `true` on `DataTable`
|
|
481
|
+
2. The header does **not** set `sortable: false`
|
|
482
|
+
3. The header has a `title` or `titleI18n` (untitled / action columns are not sortable)
|
|
483
|
+
|
|
484
|
+
Clicking a sortable header cycles `asc` → `desc` on the same column, or starts at `asc` when switching columns. Changing sort resets the page to `1` and emits `@change`.
|
|
485
|
+
|
|
486
|
+
Use `sortKey` when the display `field` (and slot name) differ from the backend sort column:
|
|
487
|
+
|
|
488
|
+
```ts
|
|
489
|
+
const headers = computed<TableHeader[]>(() => [
|
|
490
|
+
{
|
|
491
|
+
field: 'employee', // slot name (#employee) and display path
|
|
492
|
+
sortKey: 'employeeName', // sent in sort.field
|
|
493
|
+
title: 'Employee',
|
|
494
|
+
sortable: true,
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
field: 'department',
|
|
498
|
+
sortKey: 'department.departmentName', // nested backend path
|
|
499
|
+
title: 'Department',
|
|
500
|
+
sortable: true,
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
field: 'status',
|
|
504
|
+
title: 'Status',
|
|
505
|
+
sortable: true,
|
|
506
|
+
// no sortKey → sort.field is 'status'
|
|
507
|
+
},
|
|
508
|
+
])
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
When the user clicks **Employee**, the emitted sort is `{ field: 'employeeName', order: 'asc' }`. The active sort indicator on the header tracks the resolved key.
|
|
512
|
+
|
|
513
|
+
---
|
|
514
|
+
|
|
515
|
+
### Selection
|
|
516
|
+
|
|
517
|
+
- Selection is **on by default** (standalone and inside `Screen`, unless `Screen` sets `hideSelectable`).
|
|
518
|
+
- Pass `hideSelectable` to disable the checkbox column; this overrides Screen’s `forceSelectable`.
|
|
519
|
+
- Pass `isRowSelectable` when only some visible rows may be selected. Disabled rows remain visible, render a disabled checkbox, and are excluded from select-all and emitted selections.
|
|
520
|
+
- Bind with `v-model:selectedRows` or listen to `@select` / `@update:selectedRows`.
|
|
521
|
+
- Row ids come from `keyField` (supports nested paths). Selections that no longer appear in the loaded row set are pruned automatically.
|
|
522
|
+
- Header checkbox supports select-all / indeterminate state for the **current selectable scope** (current page in flat mode; loaded tree nodes in tree mode).
|
|
523
|
+
- In **tree mode**, parent selection cascades to loaded descendants; parents can show an indeterminate checkbox when only some descendants are selected.
|
|
524
|
+
- Clicking a checkbox does not emit `@rowClick`.
|
|
525
|
+
|
|
526
|
+
```ts
|
|
527
|
+
interface SelectionState {
|
|
528
|
+
selected: any[]
|
|
529
|
+
all: boolean
|
|
530
|
+
indeterminate: boolean
|
|
531
|
+
}
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
---
|
|
535
|
+
|
|
536
|
+
### Pagination
|
|
537
|
+
|
|
538
|
+
The footer renders only when:
|
|
539
|
+
|
|
540
|
+
```ts
|
|
541
|
+
showPagination && pageInfo && pageInfo.totalPages > 1
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
`pageInfo.currentPage` and `pageInfo.itemsPerPage` sync into internal state when they change. Changing page or limit emits `@change` (and `@update:itemsPerPage` for limit).
|
|
545
|
+
|
|
546
|
+
```ts
|
|
547
|
+
interface PageInfo {
|
|
548
|
+
currentPage: number
|
|
549
|
+
totalPages: number
|
|
550
|
+
totalItems?: number
|
|
551
|
+
itemsPerPage?: number
|
|
552
|
+
}
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
### Types
|
|
558
|
+
|
|
559
|
+
```ts
|
|
560
|
+
export type DataTablePaginationProps = Omit<PaginationProps, 'currentPage' | 'totalPages'>
|
|
561
|
+
|
|
562
|
+
export interface PaginationConfig {
|
|
563
|
+
page: number
|
|
564
|
+
limit: number
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export interface SortConfig {
|
|
568
|
+
field: string
|
|
569
|
+
order: 'asc' | 'desc' | ''
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export interface TableState {
|
|
573
|
+
pagination: PaginationConfig
|
|
574
|
+
sort: SortConfig
|
|
575
|
+
filter: Record<string, any>
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
export interface FilterConfig {
|
|
579
|
+
[key: string]: any
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
export interface TableFilter {
|
|
583
|
+
pagination: PaginationConfig
|
|
584
|
+
sort?: SortConfig
|
|
585
|
+
filter: FilterConfig
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export interface TableHeader {
|
|
589
|
+
field: string
|
|
590
|
+
title: string
|
|
591
|
+
titleI18n?: string
|
|
592
|
+
/**
|
|
593
|
+
* Key sent to the backend when sorting this column.
|
|
594
|
+
* Falls back to `field` when omitted.
|
|
595
|
+
* Use when the display field differs from the DB column
|
|
596
|
+
* (e.g. field: 'employee' + slot, sortKey: 'employeeName').
|
|
597
|
+
*/
|
|
598
|
+
sortKey?: string
|
|
599
|
+
width?: string
|
|
600
|
+
minWidth?: string
|
|
601
|
+
sortable?: boolean
|
|
602
|
+
/** `false` pins this column when the table sets `resizable`. */
|
|
603
|
+
resizable?: boolean
|
|
604
|
+
hideOnMobile?: boolean
|
|
605
|
+
align?: 'left' | 'center' | 'right'
|
|
606
|
+
format?: (value: any, row?: any) => string
|
|
607
|
+
class?: string | ((value: any, row?: any) => string)
|
|
608
|
+
capitalize?: boolean
|
|
609
|
+
addStatusColor?: boolean
|
|
610
|
+
type?: 'text' | 'price' | 'date' | 'number'
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
export interface DataTableProps {
|
|
614
|
+
rows: any[]
|
|
615
|
+
selectedRows?: any[]
|
|
616
|
+
headers: TableHeader[]
|
|
617
|
+
keyField?: string
|
|
618
|
+
loading?: boolean
|
|
619
|
+
hideSelectable?: boolean
|
|
620
|
+
/** Return false to keep a row visible while disabling its selection checkbox. */
|
|
621
|
+
isRowSelectable?: (row: any) => boolean
|
|
622
|
+
// …empty / pagination / visual props…
|
|
623
|
+
sortable?: boolean
|
|
624
|
+
/** Rounded container corners. Set `false` for sharp edges. @default true */
|
|
625
|
+
rounded?: boolean
|
|
626
|
+
variant?: 'default' | 'raised'
|
|
627
|
+
headerVariant?: 'default' | 'minimal'
|
|
628
|
+
size?: 'xs' | 'sm' | 'md' | 'lg'
|
|
629
|
+
/** Async loader for nested rows; result cached inside DataTable. */
|
|
630
|
+
loadChildren?: (row: any) => Promise<any[]>
|
|
631
|
+
/** Indent (px) per tree depth on the first column. @default 20 */
|
|
632
|
+
treeIndent?: number
|
|
633
|
+
/**
|
|
634
|
+
* When `true` (default), viewports below Tailwind `md` render stacked cards.
|
|
635
|
+
* Set `false` for always-table + horizontal scroll.
|
|
636
|
+
*/
|
|
637
|
+
responsive?: boolean
|
|
638
|
+
/** Opt in to drag-to-resize column boundaries. @default false */
|
|
639
|
+
resizable?: boolean
|
|
640
|
+
/** Stable key for persisting column widths. Separate from `keyField`. */
|
|
641
|
+
persistenceKey?: string
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export interface ColumnResizePayload {
|
|
645
|
+
field: string
|
|
646
|
+
width: number | null
|
|
647
|
+
previousWidth: number | null
|
|
648
|
+
source: 'pointer' | 'keyboard' | 'reset'
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/** Versioned local-storage payload; widths keyed by `header.field`. */
|
|
652
|
+
export interface ColumnWidthsState {
|
|
653
|
+
version: number
|
|
654
|
+
widths: Record<string, number>
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export interface SelectionState {
|
|
658
|
+
selected: any[]
|
|
659
|
+
all: boolean
|
|
660
|
+
indeterminate: boolean
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
export interface RowClickPayload {
|
|
664
|
+
row: any
|
|
665
|
+
index: number
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
export interface ExpandPayload {
|
|
669
|
+
row: any
|
|
670
|
+
expanded: boolean
|
|
671
|
+
children?: any[]
|
|
672
|
+
depth: number
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/** Internal flattened visible row used when tree mode is on. */
|
|
676
|
+
export interface DataTableFlatRow {
|
|
677
|
+
row: any
|
|
678
|
+
id: any
|
|
679
|
+
depth: number
|
|
680
|
+
parentId: any | null
|
|
681
|
+
isLastSibling: boolean
|
|
682
|
+
ancestorLastFlags: boolean[]
|
|
683
|
+
index: number
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Provided by Screen to descendants via provide/inject.
|
|
688
|
+
* - forceSelectable → enable row selection for bulk-delete
|
|
689
|
+
* - onTableChange → merge sort/pagination into Screen refetch
|
|
690
|
+
* (undefined when DataTable is standalone)
|
|
691
|
+
*/
|
|
692
|
+
export interface ScreenContext {
|
|
693
|
+
forceSelectable: boolean
|
|
694
|
+
onTableChange?: (state: TableState) => void
|
|
695
|
+
}
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
---
|
|
699
|
+
|
|
700
|
+
### `TableHeader` schema
|
|
701
|
+
|
|
702
|
+
| Property | Type | Description |
|
|
703
|
+
| :--------------- | :---------------------------------------- | :---------- |
|
|
704
|
+
| `field` | `string` | **Required.** Value path on the row (dot-notation supported) and the named slot for custom cells. |
|
|
705
|
+
| `title` | `string` | Column label. Required for a column to be sortable. |
|
|
706
|
+
| `titleI18n` | `string` | i18n key for the label (takes priority over `title`). |
|
|
707
|
+
| `sortKey` | `string` | Backend sort field. Defaults to `field`. |
|
|
708
|
+
| `width` | `string` | Fixed width. CSS length (`'120px'`, `'22%'`) → inline style; Tailwind utility (`'w-32'`) → class. |
|
|
709
|
+
| `minWidth` | `string` | Minimum width. Same dual mode as `width` (`'120px'` vs `'min-w-40'`). |
|
|
710
|
+
| `sortable` | `boolean` | Set `false` to opt out when the table has `sortable`. Default: allowed. |
|
|
711
|
+
| `resizable` | `boolean` | Set `false` to pin this column when the table has `resizable`. Use for action / checkbox-like / fixed-width columns. Default: allowed. |
|
|
712
|
+
| `hideOnMobile` | `boolean` | Hide column below the `md` breakpoint (table mode and stacked cards). |
|
|
713
|
+
| `align` | `'left' \| 'center' \| 'right'` | Cell and header alignment. Default `'left'`. |
|
|
714
|
+
| `format` | `(value, row?) => string` | Custom formatter. Return plain text or HTML (rendered via `v-html`). Takes priority over `type`. |
|
|
715
|
+
| `class` | `string \| ((value, row?) => string)` | Static or dynamic classes on the value cell. |
|
|
716
|
+
| `capitalize` | `boolean` | Apply `capitalize` to the cell. |
|
|
717
|
+
| `addStatusColor` | `boolean` | Apply semantic text color from the cell value (see below). |
|
|
718
|
+
| `type` | `'text' \| 'price' \| 'date' \| 'number'` | Built-in renderer when no slot / `format` is used. |
|
|
719
|
+
|
|
720
|
+
#### Built-in `type` rendering
|
|
721
|
+
|
|
722
|
+
| Value | Output |
|
|
723
|
+
| :------- | :----- |
|
|
724
|
+
| `text` | String (default). `null` / `undefined` → `'-'`. |
|
|
725
|
+
| `number` | `Intl.NumberFormat('en-US')`. |
|
|
726
|
+
| `price` | Renders the `Price` component. |
|
|
727
|
+
| `date` | Renders the `DateTime` component. |
|
|
728
|
+
|
|
729
|
+
#### `addStatusColor` map
|
|
730
|
+
|
|
731
|
+
Normalized (lowercased, separators stripped) values:
|
|
732
|
+
|
|
733
|
+
| Value | Style |
|
|
734
|
+
| :---- | :---- |
|
|
735
|
+
| `active`, `completed`, `success` | success |
|
|
736
|
+
| `pending`, `warning`, `medium` | warning |
|
|
737
|
+
| `cancelled`, `failed`, `error`, `high` | destructive |
|
|
738
|
+
| `info` | info |
|
|
739
|
+
| `inactive`, `low` | muted |
|
|
740
|
+
|
|
741
|
+
---
|
|
742
|
+
|
|
743
|
+
### Slots
|
|
744
|
+
|
|
745
|
+
| Slot | Props | Description |
|
|
746
|
+
| :--------------- | :----------------------------- | :---------- |
|
|
747
|
+
| `[header.field]` | `{ value, row, index, field }` | Custom cell content. Example: `#name="{ value, row }"`. Overrides built-in `type` / `format` for that column. |
|
|
748
|
+
| `empty` | — | Replaces the entire empty state. |
|
|
749
|
+
| `empty-action` | — | Action slot inside the default `Empty` state. |
|
|
750
|
+
|
|
751
|
+
---
|
|
752
|
+
|
|
753
|
+
### Screen context (automatic behaviour)
|
|
754
|
+
|
|
755
|
+
When `DataTable` is rendered under `Screen` (via `:table` / `views` or `#table`), it injects `ScreenContext` and:
|
|
756
|
+
|
|
757
|
+
- **Enables row selection** when Screen’s `hideSelectable` is false (`forceSelectable`).
|
|
758
|
+
- **Forwards sort and pagination** to Screen’s refetch via `onTableChange` — no extra `@change` wiring needed. Sort payloads respect `sortKey`.
|
|
759
|
+
|
|
760
|
+
`hideSelectable` on `DataTable` still wins if you need a non-selectable table inside Screen.
|
|
761
|
+
|
|
762
|
+
Standalone usage (no Screen): selection is on by default; listen to `@change` yourself.
|
|
763
|
+
|
|
764
|
+
---
|
|
765
|
+
|
|
766
|
+
### Standalone usage
|
|
767
|
+
|
|
768
|
+
```vue
|
|
769
|
+
<script setup lang="ts">
|
|
770
|
+
import { ref, onMounted } from 'vue'
|
|
771
|
+
import { DataTable } from 'vlite3'
|
|
772
|
+
import type { TableHeader, TableState } from 'vlite3'
|
|
773
|
+
|
|
774
|
+
const headers: TableHeader[] = [
|
|
775
|
+
{ field: 'employee', sortKey: 'employeeName', title: 'Employee', sortable: true },
|
|
776
|
+
{ field: 'email', title: 'Email', sortable: true },
|
|
777
|
+
{ field: 'salary', title: 'Salary', type: 'price', align: 'right', sortable: true },
|
|
778
|
+
{ field: 'joined', title: 'Joined', type: 'date', sortable: true },
|
|
779
|
+
{ field: 'status', title: 'Status', capitalize: true, addStatusColor: true, sortable: true },
|
|
780
|
+
]
|
|
781
|
+
|
|
782
|
+
const rows = ref([])
|
|
783
|
+
const loading = ref(false)
|
|
784
|
+
const pageInfo = ref()
|
|
785
|
+
const selectedRows = ref([])
|
|
786
|
+
|
|
787
|
+
const fetchData = async (state?: TableState) => {
|
|
788
|
+
loading.value = true
|
|
789
|
+
// state.sort.field is 'employeeName' when the Employee column is sorted
|
|
790
|
+
const res = await myApi.getEmployees(state)
|
|
791
|
+
rows.value = res.items
|
|
792
|
+
pageInfo.value = res.pageInfo
|
|
793
|
+
loading.value = false
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
onMounted(() => fetchData())
|
|
797
|
+
</script>
|
|
798
|
+
|
|
799
|
+
<template>
|
|
800
|
+
<DataTable
|
|
801
|
+
v-model:selected-rows="selectedRows"
|
|
802
|
+
:rows="rows"
|
|
803
|
+
:headers="headers"
|
|
804
|
+
:loading="loading"
|
|
805
|
+
:page-info="pageInfo"
|
|
806
|
+
sortable
|
|
807
|
+
size="md"
|
|
808
|
+
@change="fetchData"
|
|
809
|
+
@row-click="({ row }) => openDetail(row)">
|
|
810
|
+
<template #employee="{ row }">
|
|
811
|
+
<div class="flex items-center gap-3">
|
|
812
|
+
<img v-if="row.avatar" :src="row.avatar" class="w-9 h-9 rounded-full object-cover" />
|
|
813
|
+
<div class="flex flex-col">
|
|
814
|
+
<span class="font-medium text-sm">{{ row.employeeName }}</span>
|
|
815
|
+
<span class="text-xs text-muted-foreground">{{ row.employeeId }}</span>
|
|
816
|
+
</div>
|
|
817
|
+
</div>
|
|
818
|
+
</template>
|
|
819
|
+
</DataTable>
|
|
820
|
+
</template>
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
---
|
|
824
|
+
|
|
825
|
+
### Usage inside Screen (recommended)
|
|
826
|
+
|
|
827
|
+
```vue
|
|
828
|
+
<!-- EmployeeTable.vue -->
|
|
829
|
+
<script setup lang="ts">
|
|
830
|
+
import { computed } from 'vue'
|
|
831
|
+
import { DataTable, type TableHeader } from 'vlite3'
|
|
832
|
+
|
|
833
|
+
defineProps<{ data: any[]; loading: boolean; delete?: Function }>()
|
|
834
|
+
|
|
835
|
+
const headers = computed<TableHeader[]>(() => [
|
|
836
|
+
{
|
|
837
|
+
field: 'employee',
|
|
838
|
+
sortKey: 'employeeName',
|
|
839
|
+
title: 'Employee',
|
|
840
|
+
sortable: true,
|
|
841
|
+
},
|
|
842
|
+
{ field: 'email', title: 'Email', sortable: true },
|
|
843
|
+
{
|
|
844
|
+
field: 'department',
|
|
845
|
+
sortKey: 'department.departmentName',
|
|
846
|
+
title: 'Department',
|
|
847
|
+
sortable: true,
|
|
848
|
+
},
|
|
849
|
+
{ field: 'status', title: 'Status', sortable: true, capitalize: true, addStatusColor: true },
|
|
850
|
+
{ field: 'actions', title: '', align: 'right' },
|
|
851
|
+
])
|
|
852
|
+
</script>
|
|
853
|
+
|
|
854
|
+
<template>
|
|
855
|
+
<DataTable :headers="headers" :rows="data" sortable :loading="loading">
|
|
856
|
+
<template #employee="{ row }">
|
|
857
|
+
<div class="flex items-center gap-3">
|
|
858
|
+
<img
|
|
859
|
+
v-if="row.avatar"
|
|
860
|
+
:src="row.avatar"
|
|
861
|
+
class="w-9 h-9 rounded-full object-cover border shrink-0" />
|
|
862
|
+
<div
|
|
863
|
+
v-else
|
|
864
|
+
class="w-9 h-9 rounded-full bg-muted flex items-center justify-center text-sm font-semibold shrink-0">
|
|
865
|
+
{{ row.employeeName?.charAt(0) }}
|
|
866
|
+
</div>
|
|
867
|
+
<div class="flex flex-col min-w-0">
|
|
868
|
+
<span class="font-medium text-sm truncate">{{ row.employeeName }}</span>
|
|
869
|
+
<span class="text-xs text-muted-foreground">{{ row.employeeId }}</span>
|
|
870
|
+
</div>
|
|
871
|
+
</div>
|
|
872
|
+
</template>
|
|
873
|
+
<template #department="{ row }">{{ row.department?.departmentName || '-' }}</template>
|
|
874
|
+
<template #status="{ value }">
|
|
875
|
+
<Badge :variant="value === 'active' ? 'success' : 'secondary'">{{ value }}</Badge>
|
|
876
|
+
</template>
|
|
877
|
+
<template #actions="{ row }">
|
|
878
|
+
<div class="flex justify-end gap-1">
|
|
879
|
+
<Button
|
|
880
|
+
variant="ghost"
|
|
881
|
+
size="sm"
|
|
882
|
+
icon="lucide:trash-2"
|
|
883
|
+
class="text-red-500"
|
|
884
|
+
@click="props.delete?.([row])" />
|
|
885
|
+
</div>
|
|
886
|
+
</template>
|
|
887
|
+
</DataTable>
|
|
888
|
+
</template>
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
```vue
|
|
892
|
+
<!-- EmployeesPage.vue -->
|
|
893
|
+
<template>
|
|
894
|
+
<Screen
|
|
895
|
+
name="employees"
|
|
896
|
+
title="Employees"
|
|
897
|
+
:data="items"
|
|
898
|
+
:loading="loading"
|
|
899
|
+
:page-info="pageInfo"
|
|
900
|
+
:table="EmployeeTable"
|
|
901
|
+
:refetch="handleRefetch"
|
|
902
|
+
@delete="handleDelete" />
|
|
903
|
+
</template>
|
|
904
|
+
```
|
|
905
|
+
|
|
906
|
+
> Clicking the **Employee** column header sends `{ sort: { field: 'employeeName', order: 'asc' } }` to `handleRefetch` — the backend-friendly key, not the slot name.
|
|
907
|
+
|
|
908
|
+
---
|
|
909
|
+
|
|
910
|
+
### Related exports
|
|
911
|
+
|
|
912
|
+
| Export | Notes |
|
|
913
|
+
| :---------------- | :---- |
|
|
914
|
+
| `DataTable` | Main component. |
|
|
915
|
+
| `DataTableHeader` | Internal column header (also exported). |
|
|
916
|
+
| `DataTableRow` | Internal row renderer (also exported); hosts tree chrome + `TreeConnectors` in tree mode. |
|
|
917
|
+
| Types from `./types` | `TableHeader`, `DataTableProps`, `TableState`, `TableFilter`, `SelectionState`, `RowClickPayload`, `ExpandPayload`, `ColumnResizePayload`, `ColumnWidthsState`, `DataTableFlatRow`, `ScreenContext`, `SCREEN_CONTEXT_KEY`, etc. |
|
|
918
|
+
|
|
919
|
+
Tree expansion state lives in the internal `useDataTableTree` composable, and column
|
|
920
|
+
resizing in `useDataTableColumnResize` (neither is a public package export). Connector drawing is shared via `TreeConnectors` / `buildTreeConnectorSegments` under `src/components/TreeConnectors` (same primitive as [`FileTree`](../advanced/file-tree.md)).
|
|
921
|
+
|
|
922
|
+
`DataTableToolbar` lives beside these files as a search/actions toolbar primitive (`v-model` search, `left` / `right` / `delete` slots). It is **not** wired into `DataTable` and is **not** re-exported from the package entry — compose it yourself above the table if needed.
|