@dazzadev/vuetify-datatable 1.0.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -0
- package/dist/components/DataTable.vue.d.ts +24 -3
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +23 -0
- package/dist/vuetify-datatable.js +647 -325
- package/dist/vuetify-datatable.umd.cjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,6 +44,123 @@ import { DataTable } from "@dazzadev/vuetify-datatable";
|
|
|
44
44
|
</template>
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
## Row Selection
|
|
48
|
+
|
|
49
|
+
Set `showSelect` and bind `v-model` to hold the selected keys. **The key comes from `itemValue`**,
|
|
50
|
+
so point it at whatever your bulk endpoint expects — not necessarily `id`.
|
|
51
|
+
|
|
52
|
+
```vue
|
|
53
|
+
<DataTable
|
|
54
|
+
v-model="selected"
|
|
55
|
+
:headers="headers"
|
|
56
|
+
:items="items"
|
|
57
|
+
:totalItems="totalItems"
|
|
58
|
+
item-value="uuid"
|
|
59
|
+
show-select
|
|
60
|
+
@onLoadData="loadData"
|
|
61
|
+
>
|
|
62
|
+
<template #selection-actions="{ count, clear }">
|
|
63
|
+
<div v-if="count" class="d-flex align-center ga-2 pa-2">
|
|
64
|
+
<span>{{ count }} selected</span>
|
|
65
|
+
<v-btn size="small" @click="applyToSelection">Apply</v-btn>
|
|
66
|
+
<v-btn size="small" variant="text" @click="clear">Clear</v-btn>
|
|
67
|
+
</div>
|
|
68
|
+
</template>
|
|
69
|
+
</DataTable>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`selectStrategy` decides what the header checkbox does: `page` marks the current page only, `all`
|
|
73
|
+
marks every loaded row, `single` allows one row at a time. With server-side pagination `page` is
|
|
74
|
+
usually what you want — the table only holds the rows it has fetched.
|
|
75
|
+
|
|
76
|
+
## Wide Tables
|
|
77
|
+
|
|
78
|
+
When the columns don't fit, the table helps the user find and keep what they need. Nothing of
|
|
79
|
+
this shows while every column fits.
|
|
80
|
+
|
|
81
|
+
- **Hidden columns indicator**: a fade on the side with more columns, a round arrow on the header
|
|
82
|
+
row that scrolls about 300 px, and a "Scroll to see more columns" hint above it until the first
|
|
83
|
+
scroll.
|
|
84
|
+
- **Pinned actions column**: the header with key `actions` always goes last and sticks to the
|
|
85
|
+
right edge, with a shadow while columns pass under it.
|
|
86
|
+
- **Column chooser**: a "Columns" button above the table to show, hide, search and reorder
|
|
87
|
+
columns (drag, or the arrow keys on the handle). It reads "Columns · N hidden" while columns are
|
|
88
|
+
hidden, and stays visible in that case even if the rest fits. `actions`, expand and select
|
|
89
|
+
columns are never listed.
|
|
90
|
+
|
|
91
|
+
The choices are saved in `localStorage`, keyed by the set of header keys. Texts and the storage
|
|
92
|
+
key can be set in the global config:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
app.use(
|
|
96
|
+
createDataTableConfig({
|
|
97
|
+
texts: {
|
|
98
|
+
columns: () => i18n.global.t("dataTable.columns"),
|
|
99
|
+
hiddenColumns: (count) => i18n.global.t("dataTable.hiddenColumns", { count }, count),
|
|
100
|
+
scrollHint: "Desliza para ver más columnas",
|
|
101
|
+
},
|
|
102
|
+
storageKey: (key) => `${tenant}:${key}`,
|
|
103
|
+
}),
|
|
104
|
+
);
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Each text accepts a string or a function, which is read on every render so it follows the
|
|
108
|
+
current locale. Available texts: `columns`, `hiddenColumns`, `searchColumns`, `showAllColumns`,
|
|
109
|
+
`hideAllColumns`, `resetColumns`, `moveColumn`, `scrollHint`, `scrollLeft`, `scrollRight`.
|
|
110
|
+
|
|
111
|
+
Attributes that are not props (`row-props`, `density`, `hover`…) are passed to the inner
|
|
112
|
+
`v-data-table-server`.
|
|
113
|
+
|
|
114
|
+
### Custom column chooser
|
|
115
|
+
|
|
116
|
+
The `column-chooser` slot replaces the default button and dropdown, for example with a dialog.
|
|
117
|
+
It is shown in the same place and under the same conditions as the default one. The table keeps
|
|
118
|
+
the state and saves it; the slot only renders it.
|
|
119
|
+
|
|
120
|
+
```vue
|
|
121
|
+
<DataTable :headers="headers" :items="items" @onLoadData="loadData">
|
|
122
|
+
<template #column-chooser="{ columns, label, setVisible, move, reset }">
|
|
123
|
+
<v-btn size="small" @click="dialog = true">{{ label }}</v-btn>
|
|
124
|
+
<v-dialog v-model="dialog" max-width="420">
|
|
125
|
+
<v-card title="Columns">
|
|
126
|
+
<v-list>
|
|
127
|
+
<v-list-item v-for="column in columns" :key="column.key">
|
|
128
|
+
<v-checkbox-btn
|
|
129
|
+
:model-value="column.visible"
|
|
130
|
+
:label="column.title"
|
|
131
|
+
@update:model-value="setVisible(column.key, !!$event)"
|
|
132
|
+
/>
|
|
133
|
+
<template #append>
|
|
134
|
+
<v-btn icon="mdi-arrow-up" variant="text" size="small" @click="move(column.key, -1)" />
|
|
135
|
+
<v-btn icon="mdi-arrow-down" variant="text" size="small" @click="move(column.key, 1)" />
|
|
136
|
+
</template>
|
|
137
|
+
</v-list-item>
|
|
138
|
+
</v-list>
|
|
139
|
+
<v-card-actions>
|
|
140
|
+
<v-btn @click="reset">Reset</v-btn>
|
|
141
|
+
</v-card-actions>
|
|
142
|
+
</v-card>
|
|
143
|
+
</v-dialog>
|
|
144
|
+
</template>
|
|
145
|
+
</DataTable>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
| Slot prop | Type | Description |
|
|
149
|
+
| ------------- | -------------------------------------------- | ------------------------------------------------- |
|
|
150
|
+
| `columns` | `DataTableColumn[]` | `{ key, title, visible }` in the current order |
|
|
151
|
+
| `hiddenCount` | `number` | How many columns are hidden |
|
|
152
|
+
| `label` | `string` | "Columns", or "Columns · N hidden" |
|
|
153
|
+
| `setVisible` | `(key: string, visible: boolean) => void` | Shows or hides one column |
|
|
154
|
+
| `toggleAll` | `() => void` | Shows all, or hides all when every one is visible |
|
|
155
|
+
| `move` | `(key: string, step: -1 \| 1) => void` | Moves a column one place up or down |
|
|
156
|
+
| `place` | `(key: string, targetKey: string) => void` | Moves a column to another one's position (drag) |
|
|
157
|
+
| `reset` | `() => void` | Restores the original order and visibility |
|
|
158
|
+
|
|
159
|
+
To only restyle the default chooser, target its classes: `.vdt-columns__button` (the button),
|
|
160
|
+
`.vdt-columns` (the dropdown card), `.vdt-columns__list`, `.vdt-columns__item` and
|
|
161
|
+
`.vdt-columns__handle`. The dropdown is rendered in Vuetify's overlay container, so its rules
|
|
162
|
+
must not be scoped to the table.
|
|
163
|
+
|
|
47
164
|
## Icon Configuration
|
|
48
165
|
|
|
49
166
|
Icons can be configured at 4 levels of priority (highest to lowest):
|
|
@@ -116,6 +233,9 @@ If no configuration is provided, the component uses Material Design Icons (inclu
|
|
|
116
233
|
| `itemValue` | `string` | `'id'` | Unique item identifier key |
|
|
117
234
|
| `tableClass` | `string` | `'border rounded-md mt-5'` | CSS class for the table |
|
|
118
235
|
| `showExpand` | `boolean` | `false` | Show expandable rows |
|
|
236
|
+
| `showSelect` | `boolean` | `false` | Show a checkbox column for row selection |
|
|
237
|
+
| `selectStrategy` | `'page' \| 'all' \| 'single'` | `'page'` | How the header checkbox selects rows |
|
|
238
|
+
| `modelValue` | `(string \| number)[]` | `[]` | Selected keys, taken from `itemValue`. Use with `v-model` |
|
|
119
239
|
| `showViewButton` | `boolean` | `false` | Show view action button |
|
|
120
240
|
| `showEditButton` | `boolean` | `true` | Show edit action button |
|
|
121
241
|
| `showDeleteButton` | `boolean` | `true` | Show delete action button |
|
|
@@ -141,6 +261,7 @@ If no configuration is provided, the component uses Material Design Icons (inclu
|
|
|
141
261
|
| `editItem` | `T` | Triggered when edit button is clicked |
|
|
142
262
|
| `deleteItem` | `T` | Triggered when delete is confirmed |
|
|
143
263
|
| `viewItem` | `T` | Triggered when view button is clicked |
|
|
264
|
+
| `update:modelValue` | `(string \| number)[]` | Triggered when the selection changes |
|
|
144
265
|
|
|
145
266
|
## Slots
|
|
146
267
|
|
|
@@ -155,6 +276,7 @@ If no configuration is provided, the component uses Material Design Icons (inclu
|
|
|
155
276
|
| `edit-icon` | Custom edit icon |
|
|
156
277
|
| `delete-icon` | Custom delete icon |
|
|
157
278
|
| `item.tfoot` | Table footer content |
|
|
279
|
+
| `selection-actions` | Bar above the table, for bulk actions. Only rendered when `showSelect`. Receives `{ selected, count, clear }` |
|
|
158
280
|
|
|
159
281
|
## Peer Dependencies
|
|
160
282
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { TableHeader } from '../types';
|
|
1
|
+
import type { TableHeader, DataTableColumn } from '../types';
|
|
2
2
|
declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
3
3
|
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{
|
|
4
4
|
readonly onOnLoadData?: ((...args: any[]) => any) | undefined;
|
|
5
5
|
readonly onEditItem?: ((...args: any[]) => any) | undefined;
|
|
6
6
|
readonly onDeleteItem?: ((...args: any[]) => any) | undefined;
|
|
7
7
|
readonly onViewItem?: ((...args: any[]) => any) | undefined;
|
|
8
|
-
|
|
8
|
+
readonly "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
|
|
9
|
+
} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, "onOnLoadData" | "onEditItem" | "onDeleteItem" | "onViewItem" | "onUpdate:modelValue"> & {
|
|
9
10
|
tableClass?: string;
|
|
10
11
|
headers?: TableHeader[];
|
|
11
12
|
items?: T[];
|
|
@@ -15,6 +16,9 @@ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>
|
|
|
15
16
|
itemsPerPage?: number;
|
|
16
17
|
search?: string;
|
|
17
18
|
showExpand?: boolean;
|
|
19
|
+
showSelect?: boolean;
|
|
20
|
+
selectStrategy?: "page" | "all" | "single";
|
|
21
|
+
modelValue?: (string | number)[];
|
|
18
22
|
showEditButton?: boolean;
|
|
19
23
|
showDeleteButton?: boolean;
|
|
20
24
|
showViewButton?: boolean;
|
|
@@ -49,6 +53,23 @@ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>
|
|
|
49
53
|
columns: any;
|
|
50
54
|
item: any;
|
|
51
55
|
}) => any) | undefined;
|
|
56
|
+
} & {
|
|
57
|
+
'column-chooser'?: (props: {
|
|
58
|
+
columns: DataTableColumn[];
|
|
59
|
+
hiddenCount: number;
|
|
60
|
+
label: string;
|
|
61
|
+
setVisible: (key: string, visible: boolean) => void;
|
|
62
|
+
toggleAll: () => void;
|
|
63
|
+
reset: () => void;
|
|
64
|
+
move: (key: string, step: -1 | 1) => void;
|
|
65
|
+
place: (key: string, targetKey: string) => void;
|
|
66
|
+
}) => any;
|
|
67
|
+
} & {
|
|
68
|
+
'selection-actions'?: (props: {
|
|
69
|
+
selected: (string | number)[];
|
|
70
|
+
count: number;
|
|
71
|
+
clear: () => void;
|
|
72
|
+
}) => any;
|
|
52
73
|
} & {
|
|
53
74
|
'before-actions'?: (props: {
|
|
54
75
|
item: any;
|
|
@@ -66,7 +87,7 @@ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>
|
|
|
66
87
|
} & {
|
|
67
88
|
'item.tfoot'?: (props: {}) => any;
|
|
68
89
|
};
|
|
69
|
-
emit: (event: "onLoadData" | "editItem" | "deleteItem" | "viewItem", ...args: any[]) => void;
|
|
90
|
+
emit: (event: "onLoadData" | "editItem" | "deleteItem" | "viewItem" | "update:modelValue", ...args: any[]) => void;
|
|
70
91
|
}>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
71
92
|
[key: string]: any;
|
|
72
93
|
}> & {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import DataTable from "./components/DataTable.vue";
|
|
|
3
3
|
import { createDataTableConfig, DATA_TABLE_CONFIG_KEY } from "./config";
|
|
4
4
|
export { DataTable };
|
|
5
5
|
export { createDataTableConfig, DATA_TABLE_CONFIG_KEY };
|
|
6
|
-
export type { DataTableConfig, DataTableIconConfig, TableHeader, SortItem, LoadDataParams, } from "./types";
|
|
6
|
+
export type { DataTableColumn, DataTableConfig, DataTableIconConfig, DataTableText, DataTableTexts, TableHeader, SortItem, LoadDataParams, } from "./types";
|
|
7
7
|
declare const _default: {
|
|
8
8
|
install(app: App): void;
|
|
9
9
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -15,10 +15,33 @@ export interface DataTableIconConfig {
|
|
|
15
15
|
edit?: string | Component;
|
|
16
16
|
delete?: string | Component;
|
|
17
17
|
}
|
|
18
|
+
/** A UI text, either fixed or read on every render (e.g. `() => i18n.global.t("key")`). */
|
|
19
|
+
export type DataTableText = string | (() => string);
|
|
20
|
+
export interface DataTableTexts {
|
|
21
|
+
columns?: DataTableText;
|
|
22
|
+
hiddenColumns?: (count: number) => string;
|
|
23
|
+
searchColumns?: DataTableText;
|
|
24
|
+
showAllColumns?: DataTableText;
|
|
25
|
+
hideAllColumns?: DataTableText;
|
|
26
|
+
resetColumns?: DataTableText;
|
|
27
|
+
moveColumn?: DataTableText;
|
|
28
|
+
scrollHint?: DataTableText;
|
|
29
|
+
scrollLeft?: DataTableText;
|
|
30
|
+
scrollRight?: DataTableText;
|
|
31
|
+
}
|
|
32
|
+
/** A column as listed by the column chooser, in its current order. */
|
|
33
|
+
export interface DataTableColumn {
|
|
34
|
+
key: string;
|
|
35
|
+
title: string;
|
|
36
|
+
visible: boolean;
|
|
37
|
+
}
|
|
18
38
|
export interface DataTableConfig {
|
|
19
39
|
icons?: DataTableIconConfig;
|
|
20
40
|
iconProps?: Record<string, unknown>;
|
|
21
41
|
tableClass?: string;
|
|
42
|
+
texts?: DataTableTexts;
|
|
43
|
+
/** Maps the localStorage key where column choices are saved (e.g. to add a tenant prefix). */
|
|
44
|
+
storageKey?: (key: string) => string;
|
|
22
45
|
}
|
|
23
46
|
export interface LoadDataParams {
|
|
24
47
|
page: number;
|