innoboxrr-vue-datatable 1.2.27 → 1.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/README.md +198 -0
- package/package.json +1 -1
- package/src/DataTable.vue +11 -1
- package/src/components/DataTableComponent.vue +1 -8
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
|
|
2
|
+
# InnoboxRR Vue DataTable
|
|
3
|
+
|
|
4
|
+
**InnoboxRR Vue DataTable** es un paquete avanzado para manejar tablas de datos en aplicaciones Vue 3, con soporte para filtros, ordenación, paginación, personalización de columnas y componentes dinámicos. Este README incluye instrucciones detalladas para configurar tanto el entorno Vue como los archivos de configuración necesarios.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Índice
|
|
9
|
+
|
|
10
|
+
1. [Instalación](#instalación)
|
|
11
|
+
2. [Configuración en Vue](#configuración-en-vue)
|
|
12
|
+
3. [Archivo de Configuración](#archivo-de-configuración)
|
|
13
|
+
4. [Uso de DataTable](#uso-de-datatable)
|
|
14
|
+
5. [Personalización](#personalización)
|
|
15
|
+
6. [CRUD y Políticas](#crud-y-políticas)
|
|
16
|
+
7. [Ejemplo Completo](#ejemplo-completo)
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Instalación
|
|
21
|
+
|
|
22
|
+
### Paso 1: Instalar el paquete
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install innoboxrr-vue-datatable innoboxrr-http-request
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Configuración en Vue
|
|
31
|
+
|
|
32
|
+
1. **Registrar el paquete:**
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
// main.js
|
|
36
|
+
import { createApp } from 'vue';
|
|
37
|
+
import App from './App.vue';
|
|
38
|
+
import DataTable from 'innoboxrr-vue-datatable';
|
|
39
|
+
|
|
40
|
+
const app = createApp(App);
|
|
41
|
+
app.component('DataTable', DataTable);
|
|
42
|
+
app.mount('#app');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
2. **Registrar los componentes globales necesarios:**
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
// main.js
|
|
49
|
+
import ClipboardInput from './components/ClipboardInput.vue';
|
|
50
|
+
|
|
51
|
+
app.component('ClipboardInput', ClipboardInput);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Archivo de Configuración
|
|
57
|
+
|
|
58
|
+
Crea un archivo de configuración, por ejemplo, `dataTableConfig.js`, para centralizar la lógica asociada a tus tablas y modelos.
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
import makeHttpRequest from 'innoboxrr-http-request';
|
|
62
|
+
import ClipboardInput from '@components/ClipboardInput.vue';
|
|
63
|
+
|
|
64
|
+
export const API_ROUTE_PREFIX = 'api.example.';
|
|
65
|
+
export const CSRF_TOKEN = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
|
66
|
+
|
|
67
|
+
export let filters = {};
|
|
68
|
+
|
|
69
|
+
export const strings = {
|
|
70
|
+
crudActions: {
|
|
71
|
+
create: { name: 'Create', icon: 'fa-plus' },
|
|
72
|
+
export: { name: 'Export', icon: 'fa-download' },
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const setFilters = (newFilters = {}) => {
|
|
77
|
+
filters = { ...filters, ...newFilters };
|
|
78
|
+
return filters;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const getFilters = () => filters;
|
|
82
|
+
|
|
83
|
+
export const crudActions = () => [
|
|
84
|
+
{
|
|
85
|
+
id: 'create',
|
|
86
|
+
name: strings.crudActions.create.name,
|
|
87
|
+
callback: 'createModel',
|
|
88
|
+
icon: strings.crudActions.create.icon,
|
|
89
|
+
route: true,
|
|
90
|
+
params: { to: { name: 'CreateExample', params: {} } },
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
export const dataTableComponents = () => ({
|
|
95
|
+
ClipboardInput,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
export const dataTableHead = () => [
|
|
99
|
+
{ id: 'id', value: 'ID', sortable: true },
|
|
100
|
+
{ id: 'name', value: 'Name', sortable: true },
|
|
101
|
+
{ id: 'description', value: 'Description', sortable: false },
|
|
102
|
+
{ id: 'link', value: 'Link', component: 'ClipboardInput', parser: (value) => ({ value }) },
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
export const dataTableSort = () => ({
|
|
106
|
+
id: 'asc',
|
|
107
|
+
name: 'asc',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
export const indexModel = (filters = {}) =>
|
|
111
|
+
makeHttpRequest('get', route(API_ROUTE_PREFIX + 'index'), { _token: CSRF_TOKEN, ...filters });
|
|
112
|
+
|
|
113
|
+
export const createModel = (data) =>
|
|
114
|
+
makeHttpRequest('post', route(API_ROUTE_PREFIX + 'create'), { _token: CSRF_TOKEN, ...data });
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Uso de DataTable
|
|
120
|
+
|
|
121
|
+
```vue
|
|
122
|
+
<template>
|
|
123
|
+
<data-table
|
|
124
|
+
title="Example Table"
|
|
125
|
+
:data-url="dataUrl"
|
|
126
|
+
data-method="get"
|
|
127
|
+
:model="model"
|
|
128
|
+
:external-filters="externalFilters"
|
|
129
|
+
:form-filters="formFilters"
|
|
130
|
+
:extra-params="extraParams"
|
|
131
|
+
:hide-columns="hideColumns"
|
|
132
|
+
:has-actions="true"
|
|
133
|
+
:has-filter="true"
|
|
134
|
+
>
|
|
135
|
+
<template v-slot:filterForm>
|
|
136
|
+
<filter-form @submit="updateFormFilters" />
|
|
137
|
+
</template>
|
|
138
|
+
</data-table>
|
|
139
|
+
</template>
|
|
140
|
+
|
|
141
|
+
<script>
|
|
142
|
+
import DataTable from 'innoboxrr-vue-datatable';
|
|
143
|
+
import FilterForm from './FilterForm.vue';
|
|
144
|
+
import * as model from './dataTableConfig';
|
|
145
|
+
|
|
146
|
+
export default {
|
|
147
|
+
components: { DataTable, FilterForm },
|
|
148
|
+
data() {
|
|
149
|
+
return {
|
|
150
|
+
dataUrl: '/api/example',
|
|
151
|
+
model,
|
|
152
|
+
externalFilters: {},
|
|
153
|
+
formFilters: {},
|
|
154
|
+
extraParams: {},
|
|
155
|
+
hideColumns: [],
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
methods: {
|
|
159
|
+
updateFormFilters(filters) {
|
|
160
|
+
this.formFilters = filters;
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
</script>
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
## Personalización
|
|
170
|
+
|
|
171
|
+
1. **Cabezeras de tabla (dataTableHead):**
|
|
172
|
+
Define las columnas de la tabla en el archivo de configuración.
|
|
173
|
+
|
|
174
|
+
2. **Filtros externos e internos:**
|
|
175
|
+
Usa `formFilters` para los filtros internos y `externalFilters` para filtros definidos fuera del componente.
|
|
176
|
+
|
|
177
|
+
3. **Componentes personalizados:**
|
|
178
|
+
Registra componentes como `ClipboardInput` para columnas dinámicas.
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## CRUD y Políticas
|
|
183
|
+
|
|
184
|
+
1. **Definir acciones CRUD (crudActions):**
|
|
185
|
+
Asigna iconos, nombres y rutas a las acciones.
|
|
186
|
+
|
|
187
|
+
2. **Petición de datos:**
|
|
188
|
+
Usa funciones como `indexModel` y `createModel` para interactuar con el backend.
|
|
189
|
+
|
|
190
|
+
3. **Políticas:**
|
|
191
|
+
Integra validaciones de acceso por políticas usando rutas predefinidas.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Ejemplo Completo
|
|
196
|
+
|
|
197
|
+
Revisa la sección de ejemplos en los apartados anteriores.
|
|
198
|
+
Para más información, consulta la [documentación oficial del paquete](https://github.com/innoboxrr/vue-datatable).
|
package/package.json
CHANGED
package/src/DataTable.vue
CHANGED
|
@@ -101,6 +101,7 @@
|
|
|
101
101
|
|
|
102
102
|
<script>
|
|
103
103
|
|
|
104
|
+
import { markRaw } from 'vue';
|
|
104
105
|
import NavDropdownComponent from './components/NavDropdownComponent.vue'
|
|
105
106
|
import IconRouteComponent from './components/IconRouteComponent.vue'
|
|
106
107
|
import IconLinkComponent from './components/IconLinkComponent.vue'
|
|
@@ -190,7 +191,7 @@
|
|
|
190
191
|
meta: [],
|
|
191
192
|
links: []
|
|
192
193
|
},
|
|
193
|
-
dataTableComponents: this.
|
|
194
|
+
dataTableComponents: this.registerComponents(),
|
|
194
195
|
sort: this.model.dataTableSort(),
|
|
195
196
|
orderBy: 'id',
|
|
196
197
|
internalSort: false,
|
|
@@ -228,6 +229,15 @@
|
|
|
228
229
|
}
|
|
229
230
|
return cols;
|
|
230
231
|
},
|
|
232
|
+
registerComponents() {
|
|
233
|
+
// Usar `markRaw` para cada componente
|
|
234
|
+
let components = Object.keys(this.model.dataTableComponents())
|
|
235
|
+
.reduce((acc, key) => {
|
|
236
|
+
acc[key] = markRaw(this.model.dataTableComponents()[key]);
|
|
237
|
+
return acc;
|
|
238
|
+
}, {});
|
|
239
|
+
return components;
|
|
240
|
+
},
|
|
231
241
|
fetchData() {
|
|
232
242
|
const requestData = {
|
|
233
243
|
method: this.dataMethod,
|
|
@@ -97,7 +97,6 @@
|
|
|
97
97
|
|
|
98
98
|
<script>
|
|
99
99
|
|
|
100
|
-
import { shallowRef } from 'vue';
|
|
101
100
|
import NavDropdownComponent from './NavDropdownComponent.vue'
|
|
102
101
|
import IconRouteComponent from './IconRouteComponent.vue'
|
|
103
102
|
import IconLinkComponent from './IconLinkComponent.vue'
|
|
@@ -134,14 +133,8 @@
|
|
|
134
133
|
},
|
|
135
134
|
emits: ['sortColumn', 'actionButtonClicked', 'actionClicked'],
|
|
136
135
|
setup(props) {
|
|
137
|
-
// Registrar componentes dinámicos
|
|
138
|
-
const components = shallowRef({
|
|
139
|
-
...props.dataTableComponents
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
// Resolver el componente dinámico desde el mapeo
|
|
143
136
|
const getComponent = (componentName) => {
|
|
144
|
-
return
|
|
137
|
+
return props.dataTableComponents[componentName] || null;
|
|
145
138
|
};
|
|
146
139
|
|
|
147
140
|
return {
|