@dazzadev/vuetify-datatable 1.1.0 → 1.2.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/README.md CHANGED
@@ -73,6 +73,94 @@ so point it at whatever your bulk endpoint expects — not necessarily `id`.
73
73
  marks every loaded row, `single` allows one row at a time. With server-side pagination `page` is
74
74
  usually what you want — the table only holds the rows it has fetched.
75
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
+
76
164
  ## Icon Configuration
77
165
 
78
166
  Icons can be configured at 4 levels of priority (highest to lowest):
@@ -187,7 +275,7 @@ If no configuration is provided, the component uses Material Design Icons (inclu
187
275
  | `view-icon` | Custom view icon |
188
276
  | `edit-icon` | Custom edit icon |
189
277
  | `delete-icon` | Custom delete icon |
190
- | `item.tfoot` | Table footer content |
278
+ | `item.tfoot` | Table footer content. Receives `{ columns }`: the visible headers, in display order |
191
279
  | `selection-actions` | Bar above the table, for bulk actions. Only rendered when `showSelect`. Receives `{ selected, count, clear }` |
192
280
 
193
281
  ## Peer Dependencies
@@ -1,4 +1,4 @@
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;
@@ -53,6 +53,17 @@ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>
53
53
  columns: any;
54
54
  item: any;
55
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;
56
67
  } & {
57
68
  'selection-actions'?: (props: {
58
69
  selected: (string | number)[];
@@ -74,7 +85,9 @@ declare const _default: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>
74
85
  item: any;
75
86
  }) => any;
76
87
  } & {
77
- 'item.tfoot'?: (props: {}) => any;
88
+ 'item.tfoot'?: (props: {
89
+ columns: TableHeader[];
90
+ }) => any;
78
91
  };
79
92
  emit: (event: "onLoadData" | "editItem" | "deleteItem" | "viewItem" | "update:modelValue", ...args: any[]) => void;
80
93
  }>) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
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;