dt-vue 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +473 -2
- package/dist/index.js +1608 -0
- package/dist/style.css +1 -0
- package/package.json +73 -4
- package/types/index.d.ts +383 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 John Benedict Palo
|
|
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,474 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dt-vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A declarative Vue 3 data table built on [TanStack Table](https://tanstack.com/table) and styled with Tailwind
|
|
4
|
+
utilities. Columns are written as components, not config objects:
|
|
5
|
+
|
|
6
|
+
```vue
|
|
7
|
+
<DtTable :data="facilities" title="Facilities" exportable totals>
|
|
8
|
+
<DtColumn field="name" header="Facility" type="category" sortable width="w-1/3" />
|
|
9
|
+
<DtColumn field="region" header="Region" type="category" sortable />
|
|
10
|
+
<DtColumn field="cases" header="Cases" type="number" sortable />
|
|
11
|
+
</DtTable>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Sorting, debounced global search, pagination, grouping with aggregates, a totals row, nested rows,
|
|
15
|
+
shift/drag range selection and Excel export are built in.
|
|
16
|
+
|
|
17
|
+
> **Status: 0.x, pre-release.** The API is still moving. Coming from 0.2? Read
|
|
18
|
+
> [Upgrading from 0.2](#upgrading-from-02) first: 0.3 changes colours, defaults and labels.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm i dt-vue @tanstack/vue-table @heroicons/vue
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`@heroicons/vue` must be 2.1 or later (the table uses the 16px icon set). `xlsx` is an **optional** peer — install it only if you want Excel export. It is loaded with a dynamic
|
|
27
|
+
import, so apps that never export do not pay for it in their bundle.
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm i xlsx # only for export
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Setup
|
|
34
|
+
|
|
35
|
+
**1. Import the tokens stylesheet once** (app entry point):
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import 'dt-vue/styles.css'
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**2. Add the package to your Tailwind content paths**, otherwise the component's utility classes are purged
|
|
42
|
+
and the table renders unstyled:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
// tailwind.config.js (Tailwind v3)
|
|
46
|
+
export default {
|
|
47
|
+
content: ['./src/**/*.{vue,js}', './node_modules/dt-vue/dist/**/*.js'],
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```css
|
|
52
|
+
/* Tailwind v4 */
|
|
53
|
+
@source "../node_modules/dt-vue/dist";
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The classes the table uses need **Tailwind 3.4 or later** in your app (`size-7`, `min-w-7`).
|
|
57
|
+
|
|
58
|
+
**3. Import the components** where you need them, or register globally:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
import DtVue from 'dt-vue'
|
|
62
|
+
|
|
63
|
+
app.use(DtVue)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Theming
|
|
67
|
+
|
|
68
|
+
The table is coloured by eleven tokens with neutral grey defaults, so it looks finished before any theming. The
|
|
69
|
+
card, header band, row washes and group rows all read them. Neutrals that are not part of a theme (body text,
|
|
70
|
+
control borders) use stock Tailwind greys. Override any token on `:root`, or on an ancestor element to scope a
|
|
71
|
+
theme to part of the page:
|
|
72
|
+
|
|
73
|
+
```css
|
|
74
|
+
:root {
|
|
75
|
+
--dt-accent: #4786eb;
|
|
76
|
+
--dt-accent-strong: #2d60b3;
|
|
77
|
+
--dt-selected: #f0f6ff;
|
|
78
|
+
--dt-hover: #f0f6ff;
|
|
79
|
+
--dt-focus-border: #629dfc;
|
|
80
|
+
--dt-focus-ring: rgb(71 134 235 / 0.2);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
| Token | Default | Used for |
|
|
85
|
+
| -------------------- | ------------------------------- | --------------------------------------------------------------------- |
|
|
86
|
+
| `--dt-accent` | `#374151` (gray-700) | Sorted column arrow, checkboxes, pressed group-by border, loading line |
|
|
87
|
+
| `--dt-accent-strong` | `#111827` (gray-900) | Text on a wash: the pressed group-by label and the current page |
|
|
88
|
+
| `--dt-focus-border` | `#9ca3af` (gray-400) | Search box and Rows select border while focused |
|
|
89
|
+
| `--dt-focus-ring` | `rgb(156 163 175 / 0.25)` | Focus rings on inputs, buttons and headers |
|
|
90
|
+
| `--dt-selected` | `#f3f4f6` (gray-100) | Selected rows, the pressed group-by toggle, the current page |
|
|
91
|
+
| `--dt-hover` | `#f9fafb` (gray-50) | Row hover |
|
|
92
|
+
| `--dt-header-bg` | `#f9fafb` (gray-50) | The header band |
|
|
93
|
+
| `--dt-border` | `#e5e7eb` (gray-200) | Card edge, header rule, row hairlines, pager rule |
|
|
94
|
+
| `--dt-radius` | `0.5rem` | Card corner radius |
|
|
95
|
+
| `--dt-shadow` | `0 1px 2px 0 rgb(16 24 40 / 0.05)` | Card shadow, a full `box-shadow` value |
|
|
96
|
+
| `--dt-group-bg` | `#f9fafb` (gray-50) | Group heading rows and grouped rows |
|
|
97
|
+
|
|
98
|
+
Old to new, if you themed 0.2:
|
|
99
|
+
|
|
100
|
+
| 0.2 token | 0.3 |
|
|
101
|
+
| -------------------- | ----------------------------------------------------------------------------- |
|
|
102
|
+
| `--dt-accent` | kept, now a neutral grey by default |
|
|
103
|
+
| `--dt-accent-strong` | kept (no longer the current page's fill: that is `--dt-selected`) |
|
|
104
|
+
| `--dt-accent-fg` | removed: the current page is a wash with `--dt-accent-strong` text, not a fill |
|
|
105
|
+
| `--dt-accent-wash` | removed: split into `--dt-selected`, `--dt-hover` and `--dt-group-bg` |
|
|
106
|
+
| `--dt-action` | removed: Export is a ghost icon button, not a filled one |
|
|
107
|
+
| `--dt-action-fg` | removed with `--dt-action` |
|
|
108
|
+
| `--dt-focus-border` | kept |
|
|
109
|
+
| `--dt-focus-ring` | kept |
|
|
110
|
+
|
|
111
|
+
## Column types
|
|
112
|
+
|
|
113
|
+
`type` drives alignment, formatting, sorting, group aggregation and what gets written to the export.
|
|
114
|
+
|
|
115
|
+
| Type | Alignment | Renders as | Aggregates to | Totals row | Exports as |
|
|
116
|
+
| ---------- | --------- | ------------- | ------------- | ---------- | ---------- |
|
|
117
|
+
| `string` | center | raw value | — | — | text |
|
|
118
|
+
| `category` | left | raw value | shared value | — | text |
|
|
119
|
+
| `number` | center | `1,234` | sum | sum | number |
|
|
120
|
+
| `percent` | center | `92.40%` | mean | — | number |
|
|
121
|
+
| `date` | center | `Jan 5, 2026` | — | — | date |
|
|
122
|
+
| `minDate` | center | `Jan 5, 2026` | earliest | earliest | date |
|
|
123
|
+
| `maxDate` | center | `Jan 5, 2026` | latest | latest | date |
|
|
124
|
+
|
|
125
|
+
All formatting goes through `Intl`; there is no date library. Control it with `locale`, `dateFormat` and
|
|
126
|
+
`numberFormat` on the table, and `decimals` on a `percent` column.
|
|
127
|
+
|
|
128
|
+
### Column props
|
|
129
|
+
|
|
130
|
+
| Prop | Type | Default | Description |
|
|
131
|
+
| ------------ | ---------- | --------- | ---------------------------------------------------- |
|
|
132
|
+
| `field` | `String` | required | Key on the row object. |
|
|
133
|
+
| `header` | `String` | `field` | Column heading. |
|
|
134
|
+
| `type` | `String` | `string` | See the table above. |
|
|
135
|
+
| `sortable` | `Boolean` | `false` | Allow sorting by clicking the header. |
|
|
136
|
+
| `align` | `String` | by type | `left` \| `center` \| `right`. |
|
|
137
|
+
| `fit` | `Boolean` | `false` | Shrink the column to its content. |
|
|
138
|
+
| `width` | `String` | `null` | Tailwind width class, e.g. `w-1/3`, `w-[180px]`. |
|
|
139
|
+
| `decimals` | `Number` | `2` | Fraction digits for `percent`. |
|
|
140
|
+
| `cellStyle` | `Function` | `null` | `(value, rowData) => styleObject`. |
|
|
141
|
+
| `cellTitle` | `Function` | `null` | `(value, rowData) => string`, the cell's `title`. |
|
|
142
|
+
| `exportable` | `Boolean` | `true` | Include this column in the export. |
|
|
143
|
+
|
|
144
|
+
### Custom cells
|
|
145
|
+
|
|
146
|
+
```vue
|
|
147
|
+
<DtColumn field="status" header="Status">
|
|
148
|
+
<template #body="{ data, value, row, column, table }">
|
|
149
|
+
<StatusBadge :status="value" />
|
|
150
|
+
</template>
|
|
151
|
+
</DtColumn>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Clicks on interactive content inside a cell (`a`, `button`, `input`, …) do not toggle row selection. Add
|
|
155
|
+
`data-dt-no-select` to opt a custom element out too.
|
|
156
|
+
|
|
157
|
+
### Conditional cell shading
|
|
158
|
+
|
|
159
|
+
```vue
|
|
160
|
+
<script setup>
|
|
161
|
+
import { heatmap } from 'dt-vue'
|
|
162
|
+
|
|
163
|
+
const rate = heatmap({ min: 0, max: 100 })
|
|
164
|
+
</script>
|
|
165
|
+
|
|
166
|
+
<template>
|
|
167
|
+
<DtColumn field="rate" header="Accomplishment" type="percent" :cell-style="rate" />
|
|
168
|
+
</template>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
`heatmap({ colors, min, max, property })` returns a `cellStyle` function. The default ten-step scale runs red
|
|
172
|
+
through amber to green; pass your own `colors` array for anything else.
|
|
173
|
+
|
|
174
|
+
For graded bands with readable text, use `bands()`:
|
|
175
|
+
|
|
176
|
+
```vue
|
|
177
|
+
<script setup>
|
|
178
|
+
import { bands } from 'dt-vue'
|
|
179
|
+
|
|
180
|
+
const rate = bands({
|
|
181
|
+
cuts: [50, 80, 95],
|
|
182
|
+
shades: [
|
|
183
|
+
['#9B272C', '#D03E45'],
|
|
184
|
+
['#F6B321', '#FED78B'],
|
|
185
|
+
['#C3F6C5', '#77D585'],
|
|
186
|
+
['#26873F', '#054A1F'],
|
|
187
|
+
],
|
|
188
|
+
labels: ['Far behind', 'Behind', 'Near target', 'Met'],
|
|
189
|
+
})
|
|
190
|
+
</script>
|
|
191
|
+
|
|
192
|
+
<template>
|
|
193
|
+
<DtColumn
|
|
194
|
+
field="rate"
|
|
195
|
+
header="Suppression"
|
|
196
|
+
type="percent"
|
|
197
|
+
:cell-style="rate"
|
|
198
|
+
:cell-title="(value) => rate.band(value)?.label" />
|
|
199
|
+
</template>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
`bands({ cuts, shades, labels, min = 0, max = 100, ink, light })` returns a `cellStyle` that gives `{ backgroundColor,
|
|
203
|
+
color }`. `n` cuts make `n + 1` bands with two shades each: band `i` covers `[cuts[i - 1] ?? min, cuts[i] ?? max)`,
|
|
204
|
+
its lower half takes the first shade and its upper half (the exact midpoint included) the second. Values below `min`
|
|
205
|
+
take the very first shade and values at or above `max` the very last. `color` is `light` (white) or `ink` (near-black),
|
|
206
|
+
whichever has the higher WCAG contrast on the shade. Blank and non-numeric values are left unstyled. A cut may lie
|
|
207
|
+
outside `min`..`max`; clamping wins.
|
|
208
|
+
|
|
209
|
+
`rate.band(value)` returns `{ index, label, background, color }`, or `null` for a blank value, which is what feeds
|
|
210
|
+
`cellTitle`. `bands()` throws a `TypeError` when `shades` is not one longer than `cuts`, a band does not have exactly
|
|
211
|
+
two shades, `cuts` do not strictly ascend, or a shade is not a hex colour (three or six digits) or `rgb(r, g, b)`.
|
|
212
|
+
|
|
213
|
+
## Table props
|
|
214
|
+
|
|
215
|
+
| Prop | Type | Default | Description |
|
|
216
|
+
| ----------------- | -------------------- | ----------------------- | ---------------------------------------------------------------- |
|
|
217
|
+
| `data` | `Array` | `[]` | Row objects. |
|
|
218
|
+
| `title` | `String` | `''` | Heading, and the default export filename. |
|
|
219
|
+
| `locale` | `String` | runtime locale | Applied to every number and date. |
|
|
220
|
+
| `dateFormat` | `Object\|Function` | medium date | `Intl.DateTimeFormatOptions`, or `(date) => string`. |
|
|
221
|
+
| `numberFormat` | `Object` | `{}` | `Intl.NumberFormatOptions` for `number` columns. |
|
|
222
|
+
| `labels` | `Object` | English | Override any UI string. |
|
|
223
|
+
| `totals` | `Boolean` | `false` | Totals row for numeric and min/max date columns; `labels.total` names it. |
|
|
224
|
+
| `bordered` | `Boolean` | `true` | Hairline under every row. `:bordered="false"` removes it. |
|
|
225
|
+
| `density` | `String` | `'compact'` | `'compact'` (12px) or `'comfortable'` (13px, roomier rows). |
|
|
226
|
+
| `pagination` | `String` | `'step'` | `'step'` (range, previous, next) or `'numbers'` (adds pages). |
|
|
227
|
+
| `mono` | `Boolean` | `false` | Monospace table text. |
|
|
228
|
+
| `overflowVisible` | `Boolean` | `false` | No overflow clipping or scroll wrapper. See below. |
|
|
229
|
+
| `loading` | `Boolean` | `false` | Skeleton rows and a progress line. See below. |
|
|
230
|
+
| `rows` | `Number` | `10` | Page size. Reactive. |
|
|
231
|
+
| `pageSizes` | `Array` | `[10,25,50,75,100]` | Page-size options. |
|
|
232
|
+
| `searchable` | `Boolean` | `true` | Show the global search box in the header bar. |
|
|
233
|
+
| `searchDebounce` | `Number` | `200` | Milliseconds before filtering. |
|
|
234
|
+
| `sortField` | `String` | `null` | Externally controlled sort column. |
|
|
235
|
+
| `sortOrder` | `Number` | `1` | `1` ascending, `-1` descending. |
|
|
236
|
+
| `groupBy` | `Object` | `null` | `{ Label: ['col'] }` — renders a "Group by Label" button. |
|
|
237
|
+
| `groupRowsBy` | `String` | `null` | Visual-only heading row whenever this field changes. |
|
|
238
|
+
| `subRows` | `String\|Function` | `'children'` | Where nested rows live. |
|
|
239
|
+
| `expandable` | `Boolean` | `true` | Expander column when the data nests. Set `false` to hide it. |
|
|
240
|
+
| `rowId` | `String` | `null` | Row identity; also what `v-model` holds. |
|
|
241
|
+
| `selectable` | `Boolean` | `false` | Checkbox column, click, shift-click and drag selection. |
|
|
242
|
+
| `exportable` | `Boolean` | `false` | Show the built-in Export icon button. |
|
|
243
|
+
| `exportFilename` | `String` | `title` | Export filename, without extension. |
|
|
244
|
+
| `sheetName` | `String` | `'Data'` | Worksheet name. |
|
|
245
|
+
|
|
246
|
+
### Toolbar
|
|
247
|
+
|
|
248
|
+
The header bar is one row that wraps: the title on the left, and on the right the search box, the group-by toggles,
|
|
249
|
+
the verbs, then your `#toolbar` slot. It shows whenever there is a `title`, search, `groupBy`, `exportable`, a
|
|
250
|
+
`#title` slot or a `#toolbar` slot, so a table with `searchable` on (the default) always has one. On a phone the
|
|
251
|
+
search takes the full width and the rest wraps under it.
|
|
252
|
+
|
|
253
|
+
- **Search** has a leading magnifier icon; its placeholder and accessible name are `labels.search`.
|
|
254
|
+
- **Group by** toggles keep their words (`labels.groupBy`) and carry `aria-pressed`. Pressing one that is already on
|
|
255
|
+
clears the grouping.
|
|
256
|
+
- **Clear grouping** (an X icon) shows only while grouped. Using it hands focus to the first group-by toggle.
|
|
257
|
+
- **Export** (a download icon) shows when `exportable`. Both icon buttons are named by an `aria-label` and show the same
|
|
258
|
+
text in a tooltip after a 300ms hover or at once on keyboard focus.
|
|
259
|
+
|
|
260
|
+
Anything of your own goes in `#toolbar`; dt-vue's tooltip is internal, so bring your own for those.
|
|
261
|
+
|
|
262
|
+
### Sorting from the keyboard
|
|
263
|
+
|
|
264
|
+
A sortable column's heading is a real `<button>`: Tab reaches it and Enter or Space sorts. `aria-sort` stays on the
|
|
265
|
+
header cell.
|
|
266
|
+
|
|
267
|
+
### Pagination
|
|
268
|
+
|
|
269
|
+
`pagination="step"` (the default) shows a **Rows** select on the left and the range with previous and next buttons on
|
|
270
|
+
the right. `pagination="numbers"` keeps the Rows select and puts the range on the left, then shows previous, a window
|
|
271
|
+
of page numbers and next. Seven pages or fewer show every number; otherwise the window keeps the first and last page
|
|
272
|
+
and the current page plus one either side, widened so the first three or last three pages show when you are among
|
|
273
|
+
them (`1 2 3 … 25`, `1 … 9 10 11 … 25`, `1 … 23 24 25`). There are no first and last buttons. The pager is hidden
|
|
274
|
+
while `loading` and when there are no rows.
|
|
275
|
+
|
|
276
|
+
### Loading and empty states
|
|
277
|
+
|
|
278
|
+
`loading` replaces the rows with still skeleton rows (up to five, or the page size if smaller), draws a 2px accent
|
|
279
|
+
line along the card's top edge that sweeps while it loads (it holds still, faint and full width, under
|
|
280
|
+
`prefers-reduced-motion`), sets `aria-busy` on the table, and announces `labels.loading` through a visually hidden
|
|
281
|
+
status region. A refetch replaces existing rows with skeletons. The `#loading` slot, when given, replaces the skeleton
|
|
282
|
+
rows with its content in one full-width cell. The totals row is hidden while loading.
|
|
283
|
+
|
|
284
|
+
An empty table shows a tile, a title (`labels.empty`, or `labels.emptySearch` while a search is active, with
|
|
285
|
+
`{query}`) and, when `labels.emptyHint` is set, a hint. The `#empty` slot renders under them as an action area and
|
|
286
|
+
receives `{ query, clearSearch }`:
|
|
287
|
+
|
|
288
|
+
```vue
|
|
289
|
+
<DtTable :data="rows" :labels="{ emptyHint: 'Check the spelling, or search by region.' }">
|
|
290
|
+
<template #empty="{ query, clearSearch }">
|
|
291
|
+
<button v-if="query" type="button" @click="clearSearch()">Clear search</button>
|
|
292
|
+
</template>
|
|
293
|
+
</DtTable>
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Density
|
|
297
|
+
|
|
298
|
+
`density="compact"` (the default) is 12px text with `px-3 py-2` cells; `"comfortable"` is 13px with `px-3 py-2.5`. Header
|
|
299
|
+
cells and group headings keep their padding in both. Numbers and dates use tabular figures.
|
|
300
|
+
|
|
301
|
+
### Labels
|
|
302
|
+
|
|
303
|
+
Pass a partial `labels` object to reword anything. Placeholders in braces are filled in.
|
|
304
|
+
|
|
305
|
+
| Key | Default | Placeholders |
|
|
306
|
+
| --------------- | -------------------------------- | --------------------------- |
|
|
307
|
+
| `search` | `Search` | |
|
|
308
|
+
| `empty` | `No entries found` | |
|
|
309
|
+
| `emptyHint` | `''` (no hint) | |
|
|
310
|
+
| `emptySearch` | `No entries match "{query}"` | `{query}` |
|
|
311
|
+
| `loading` | `Loading...` | |
|
|
312
|
+
| `export` | `Export to Excel` | |
|
|
313
|
+
| `groupBy` | `Group by {label}` | `{label}` |
|
|
314
|
+
| `groupCount` | `{count}` | `{count}` |
|
|
315
|
+
| `clearGrouping` | `Clear grouping` | |
|
|
316
|
+
| `total` | `Total` | |
|
|
317
|
+
| `rowsPerPage` | `Rows` | |
|
|
318
|
+
| `range` | `{from}–{to} of {total}` | `{from}`, `{to}`, `{total}` |
|
|
319
|
+
| `previousPage` | `Previous page` | |
|
|
320
|
+
| `nextPage` | `Next page` | |
|
|
321
|
+
| `pagination` | `Pagination` | |
|
|
322
|
+
| `expandRow` | `Expand row` | |
|
|
323
|
+
| `collapseRow` | `Collapse row` | |
|
|
324
|
+
| `selectAll` | `Select all rows on this page` | |
|
|
325
|
+
| `selectRow` | `Select row` | |
|
|
326
|
+
|
|
327
|
+
`groupCount` follows each group heading and each `groupBy` row, e.g. `'{count} facilities'`. Counts go through the
|
|
328
|
+
table's number formatting (`1,234`).
|
|
329
|
+
|
|
330
|
+
### Dropdowns in cells
|
|
331
|
+
|
|
332
|
+
By default the card clips its contents and the table scrolls horizontally inside it, which cuts off any
|
|
333
|
+
absolutely positioned menu or popover rendered in a cell. Set `overflow-visible` to remove both, so the
|
|
334
|
+
menu can extend past the table. The trade-off: a table wider than its container widens the page rather
|
|
335
|
+
than scrolling inside the card. Menus that teleport to `body` (or use `position: fixed`) do not need this.
|
|
336
|
+
|
|
337
|
+
```vue
|
|
338
|
+
<DtTable :data="rows" overflow-visible>
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Selection
|
|
342
|
+
|
|
343
|
+
`v-model` is two-way. It holds `row[rowId]` values when `rowId` is set, otherwise whole row objects, and a
|
|
344
|
+
selection assigned from outside is applied back to the table — so rows can be pre-selected.
|
|
345
|
+
|
|
346
|
+
```vue
|
|
347
|
+
<DtTable v-model="selected" :data="rows" row-id="id" selectable>
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Only top-level rows are selectable; nested rows are not.
|
|
351
|
+
|
|
352
|
+
### Slots
|
|
353
|
+
|
|
354
|
+
| Slot | Props | Purpose |
|
|
355
|
+
| --------- | ------------------------------------------------------------ | ---------------------------- |
|
|
356
|
+
| `title` | — | Replace the heading. |
|
|
357
|
+
| `toolbar` | `table`, `exportXlsx`, `grouping`, `setGrouping`, `clearGrouping` | After the built-in verbs. |
|
|
358
|
+
| `empty` | `query`, `clearSearch` | Action area under the empty state's title and hint. |
|
|
359
|
+
| `loading` | — | Replaces the skeleton rows. |
|
|
360
|
+
|
|
361
|
+
### Events
|
|
362
|
+
|
|
363
|
+
| Event | Payload | When |
|
|
364
|
+
| -------------- | ------- | ------------------------------------ |
|
|
365
|
+
| `export-error` | `Error` | Export failed, e.g. `xlsx` missing. |
|
|
366
|
+
|
|
367
|
+
### Exposed methods
|
|
368
|
+
|
|
369
|
+
```js
|
|
370
|
+
tableRef.value.table // the underlying TanStack table instance
|
|
371
|
+
await tableRef.value.exportXlsx()
|
|
372
|
+
tableRef.value.resetSelection()
|
|
373
|
+
tableRef.value.getSelectedRows()
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Export contents
|
|
377
|
+
|
|
378
|
+
The export reflects what the user is looking at: the active search, sort order, grouping order and column
|
|
379
|
+
visibility all apply, and columns marked `:exportable="false"` are left out. Pagination and expand/collapse
|
|
380
|
+
state do not apply, so the file always holds the full result set including nested rows. Numbers and dates are
|
|
381
|
+
written as real numbers and dates so Excel can total and reformat them.
|
|
382
|
+
|
|
383
|
+
## Upgrading from 0.2
|
|
384
|
+
|
|
385
|
+
0.3.0 changes the look and a few defaults. In order of how likely they are to bite:
|
|
386
|
+
|
|
387
|
+
- **Tokens.** `--dt-action`, `--dt-action-fg`, `--dt-accent-fg` and `--dt-accent-wash` are removed, with no aliases.
|
|
388
|
+
The defaults are neutral greys, not teal, so a table you never themed changes colour. New tokens: `--dt-selected`,
|
|
389
|
+
`--dt-hover`, `--dt-header-bg`, `--dt-border`, `--dt-radius`, `--dt-shadow`, `--dt-group-bg`. See [Theming](#theming)
|
|
390
|
+
for the old to new map.
|
|
391
|
+
- **`bordered` defaults to `true`.** Pass `:bordered="false"` to keep rows without hairlines.
|
|
392
|
+
- **Export and Clear grouping are icon-only.** `labels.export` now defaults to `'Export to Excel'` and is the button's
|
|
393
|
+
name and tooltip, not visible text. Find the button by its `aria-label`, not its text.
|
|
394
|
+
- **Search moves into the header bar**, so a table with no title now shows a header bar while `searchable`. The
|
|
395
|
+
`labels.search` default is `'Search'`.
|
|
396
|
+
- **The pager.** The default is `pagination="step"`. First and last buttons are gone in both modes, and the pager hides
|
|
397
|
+
while loading or empty.
|
|
398
|
+
- **Labels.** Removed: `firstPage`, `lastPage`, `results`, `unitRows`, `unitResults`, `noResults`, `pageSize`. Added:
|
|
399
|
+
`rowsPerPage`, `range`, `groupCount`, `emptyHint`, `emptySearch`, `total`. Page-size options show just the number
|
|
400
|
+
(`'25'`), not `'Show 25'`.
|
|
401
|
+
- **`loading` replaces the rows with skeleton rows** instead of adding a message row under them.
|
|
402
|
+
- **`#empty` is the action area** under the title and hint, not the whole message. Use `labels.empty` and
|
|
403
|
+
`labels.emptyHint` for the words.
|
|
404
|
+
- **The empty state is a `div[data-dt-empty]` after the `<table>`**, no longer a `<tbody>` row, so selectors aimed at
|
|
405
|
+
the empty cell break. The header row stays and `<tbody>` is empty.
|
|
406
|
+
- **Grouped rows show a `category` value only when every leaf shares it.** 0.2 repeated the first leaf's value; now a
|
|
407
|
+
column whose leaves differ is blank on the group row. Date-typed columns compare by time value.
|
|
408
|
+
- **The group count is `labels.groupCount`** (default `'{count}'`, the number with thousands separators), no longer
|
|
409
|
+
`(n)`. Reword it, for example `'({count})'` or `'{count} facilities'`.
|
|
410
|
+
- **Header labels, and number, percent and date cells, no longer wrap** (`whitespace-nowrap`).
|
|
411
|
+
- **The totals row labels itself** with `labels.total` (default `'Total'`) in the first non-numeric column that has no
|
|
412
|
+
total of its own.
|
|
413
|
+
- **Clicking a pressed group-by toggle clears grouping.**
|
|
414
|
+
- **Sortable headings are buttons.** Selectors that clicked the `<th>` should click the `<button>` inside it.
|
|
415
|
+
- **Totals cells are `<td>`**, not `<th>`.
|
|
416
|
+
- **Peers.** `@heroicons/vue` must be 2.1 or later, and the classes used need Tailwind 3.4 or later in your app
|
|
417
|
+
(`size-7`, `min-w-7`).
|
|
418
|
+
|
|
419
|
+
New in 0.3.0: `density`, `pagination`, `bands()`, `cellTitle`, the `#empty` slot props, tabular figures and keyboard
|
|
420
|
+
sorting.
|
|
421
|
+
|
|
422
|
+
## TypeScript
|
|
423
|
+
|
|
424
|
+
Declarations ship with the package — no `@types` install needed. Both components are generic over the row
|
|
425
|
+
type, so `#body` slot props and `cellStyle` are inferred:
|
|
426
|
+
|
|
427
|
+
```vue
|
|
428
|
+
<script setup lang="ts">
|
|
429
|
+
import { DtColumn, DtTable } from 'dt-vue'
|
|
430
|
+
import type { DtTableExposed } from 'dt-vue'
|
|
431
|
+
|
|
432
|
+
interface Facility { id: number; name: string; cases: number }
|
|
433
|
+
|
|
434
|
+
const rows = ref<Facility[]>([])
|
|
435
|
+
const table = ref<DtTableExposed<Facility>>()
|
|
436
|
+
</script>
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Installing the plugin also registers `DtTable` and `DtColumn` in Vue's `GlobalComponents`, so they resolve in
|
|
440
|
+
templates without an import.
|
|
441
|
+
|
|
442
|
+
## Behaviour notes
|
|
443
|
+
|
|
444
|
+
- **Sort direction on first click** follows TanStack: numeric columns sort descending first, text columns
|
|
445
|
+
ascending first.
|
|
446
|
+
- **Pagination resets to page 1** when the search text, the `data` prop or the grouping changes — and only
|
|
447
|
+
then. (TanStack's `autoResetPageIndex` is switched off deliberately: under the Vue adapter its queued reset
|
|
448
|
+
is flushed by the next `setOptions`, which lands straight after an ordinary page change and snaps the user
|
|
449
|
+
back to page 1.)
|
|
450
|
+
|
|
451
|
+
## Known limitations
|
|
452
|
+
|
|
453
|
+
- A `v-model` array mutated in place (`selected.value.push(x)`) is not picked up; assign a new array.
|
|
454
|
+
- Columns must be direct children of `<DtTable>`; they are read from the slot's vnodes, so columns wrapped
|
|
455
|
+
inside another component are not discovered.
|
|
456
|
+
- No column virtualization — use pagination for large datasets.
|
|
457
|
+
|
|
458
|
+
## Development
|
|
459
|
+
|
|
460
|
+
```bash
|
|
461
|
+
npm install
|
|
462
|
+
npm run dev # playground at /dev
|
|
463
|
+
npm run test:types # vue-tsc against the published declarations
|
|
464
|
+
npm run test:coverage
|
|
465
|
+
npm run check # tests + types + build
|
|
466
|
+
npm run build
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
`npm audit` reports advisories against `xlsx`, which is a dev dependency here for the playground and is
|
|
470
|
+
optional for consumers.
|
|
471
|
+
|
|
472
|
+
## License
|
|
473
|
+
|
|
474
|
+
MIT
|