@sulzanoks/vue-datatable 0.3.5 → 0.4.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 +479 -132
- package/dist/datatable-card.es.js +1978 -1907
- package/dist/datatable-card.umd.js +7 -7
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/Components/DatatableCard.vue +178 -113
- package/src/locales.js +48 -0
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.toolbar[data-v-
|
|
1
|
+
.toolbar[data-v-5cc7dbbd]:not(.open){display:none}.card .card-heading[data-v-5cc7dbbd]{padding:15px 20px;position:relative;height:65px}.card .card-search[data-v-5cc7dbbd]{position:absolute;top:0;right:0;margin:0;padding:0;height:100%;z-index:15;-webkit-transition:all .2s;-o-transition:all .2s;transition:all .2s;border:0;box-shadow:none;width:100%;display:none;background:#fff}.card .card-search .form-group[data-v-5cc7dbbd]{margin:0;padding:0;height:65px}.card .card-search .search-icon-left[data-v-5cc7dbbd]{left:15px;right:auto}.card .card-search .close-search[data-v-5cc7dbbd],.card .card-search .search-icon-left[data-v-5cc7dbbd]{top:50%;margin-top:-15px;line-height:30px;margin-right:10px;font-size:25px;position:absolute;right:15px;z-index:99}.card .card-search .form-control[data-v-5cc7dbbd]{width:100%;height:100%;position:absolute;border:none;box-shadow:none;left:0;top:0;margin:0;font-size:15px;text-indent:45px;background-color:#eef5f9;background-image:none}.card .card-search .close-search[data-v-5cc7dbbd]{right:15px;left:auto}.card .card-search .search-icon-left[data-v-5cc7dbbd]{top:50%;margin-top:-15px;line-height:30px;margin-right:10px;font-size:25px;position:absolute;right:15px;z-index:99;width:30px}.card .card-search.open[data-v-5cc7dbbd]{display:block}.card-heading ul.card-actions.icons[data-v-5cc7dbbd]{position:absolute;list-style:none;padding:0;margin:0}ul.card-actions.icons li[data-v-5cc7dbbd]{display:inline}.dataTables_wrapper .dataTables_paginate .paginate_button.current[data-v-5cc7dbbd],.dataTables_wrapper .dataTables_paginate .paginate_button.current[data-v-5cc7dbbd]:hover{background:unset;background-color:#00bcd4;border-color:#00bcd4;box-shadow:0 4px 5px #00bcd424,0 1px 10px #00bcd41f,0 2px 4px -1px #00bcd433}.dataTables_wrapper .dataTables_paginate .paginate_button[data-v-5cc7dbbd],.dataTables_wrapper .dataTables_paginate .paginate_button[data-v-5cc7dbbd]:hover{background:unset;border:0;border-color:#00bcd4;border-radius:30px!important;-webkit-transition:all .3s;transition:all .3s;padding:0 11px;margin:0 3px;min-width:30px;height:30px;line-height:30px;color:#999!important;font-weight:400;font-size:12px;text-transform:uppercase;background:transparent;text-align:center}.dataTables_wrapper .dataTables_paginate .paginate_button[data-v-5cc7dbbd]:hover{border:1}.card-header[data-v-5cc7dbbd]:first-child{border-radius:calc(.25rem - 1px) calc(.25rem - 1px) 0 0}.card .card-header[data-v-5cc7dbbd]{border-bottom:none;background:transparent}.card [class*=card-header-][data-v-5cc7dbbd],.card[class*=bg-][data-v-5cc7dbbd]{color:#fff}.card .card-header[data-v-5cc7dbbd]{z-index:3!important}.card [class*=card-header-][data-v-5cc7dbbd]{margin:0 15px;padding:0;position:relative}.card [class*=card-header-] .card-icon[data-v-5cc7dbbd],.card [class*=card-header-] .card-text[data-v-5cc7dbbd]{border-radius:3px;background-color:#999;padding:15px;margin-top:-20px;margin-right:15px;float:left}.card .card-header.card-header-icon i[data-v-5cc7dbbd],.card .card-header.card-header-text i[data-v-5cc7dbbd]{width:33px;height:33px;text-align:center;line-height:33px}.card[data-v-5cc7dbbd]{border:0;margin-bottom:30px;margin-top:30px;border-radius:6px;color:#333;background:#ffffff;width:100%;box-shadow:0 2px 2px #00000024,0 3px 1px -2px #0003,0 1px 5px #0000001f;box-shadow:0 1px 4px #00000024;font-size:.875rem}.card .card-header.card-header-icon .card-title[data-v-5cc7dbbd],.card .card-header.card-header-text .card-title[data-v-5cc7dbbd]{margin-top:15px;color:#3c4858}.card .card-header.card-header-icon h4[data-v-5cc7dbbd],.card .card-header.card-header-text h4[data-v-5cc7dbbd]{font-weight:300}.card .card-header .card-title[data-v-5cc7dbbd]{margin-bottom:3px}.card .card-actions[data-v-5cc7dbbd]{position:absolute;z-index:1;top:-50px;width:calc(100% - 30px);left:17px;right:17px;text-align:center}.card .card-actions[data-v-5cc7dbbd]{text-align:end}.card ul.card-actions.icons[data-v-5cc7dbbd]{position:absolute;list-style:none;padding:0;margin:0;right:10px;top:15px}ul.card-actions.icons.right-top[data-v-5cc7dbbd]{right:10px;top:15px}ul.card-actions.icons li[data-v-5cc7dbbd]{display:inline;width:100%;text-align:unset}.dropdown-menu .dropdown-item[data-v-5cc7dbbd],.dropdown-menu li>a[data-v-5cc7dbbd]{position:relative;width:auto;display:flex;flex-flow:nowrap;align-items:center;color:#333;font-weight:400;text-decoration:none;font-size:.8125rem;border-radius:.125rem;margin:0 .3125rem;transition:all .15s linear;min-width:7rem;padding:.625rem 1.25rem;overflow:hidden;line-height:1.42857143;text-overflow:ellipsis;word-wrap:break-word}.dropdown-menu .dropdown-item[data-v-5cc7dbbd],.dropdown-menu li>a[data-v-5cc7dbbd]{padding-right:1.5rem;padding-left:1.5rem}.dropdown-menu[data-v-5cc7dbbd]{position:absolute;top:100%;left:0;z-index:1000;display:none;float:left;min-width:10rem;padding:.5rem 0;margin:.125rem 0 0;font-size:1rem;color:#212529;text-align:left;list-style:none;background-color:#fff;background-clip:padding-box;border:1px solid rgba(0,0,0,.15);border-radius:.25rem;box-shadow:0 2px 2px #00000024,0 3px 1px -2px #0003,0 1px 5px #0000001f}.dropdown-menu[data-v-5cc7dbbd]{border:0;display:none;padding:.3125rem 0;transform:scale(0);transform-origin:0 0;will-change:transform,opacity;box-shadow:0 2px 5px #00000042}.dropdown-menu[data-v-5cc7dbbd]{margin:0!important}.clickable-rows tbody tr[data-v-5cc7dbbd]{cursor:pointer}
|
package/package.json
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="card" :class="cardClasses">
|
|
3
|
-
<header
|
|
4
|
-
|
|
3
|
+
<header
|
|
4
|
+
class="card-header"
|
|
5
|
+
:class="[
|
|
6
|
+
{
|
|
7
|
+
'card-header-danger': cardError && cardIcon,
|
|
8
|
+
'card-header-icon': cardIcon
|
|
9
|
+
},
|
|
10
|
+
!cardError && cardIcon ? cardIconStyle : null,
|
|
11
|
+
]"
|
|
12
|
+
>
|
|
13
|
+
<slot name="header"></slot>
|
|
5
14
|
<div v-if="cardIcon" class="card-icon">
|
|
6
15
|
<i v-if="!cardError" class="material-icons">{{ cardIcon }}</i>
|
|
7
16
|
<i v-else class="material-icons">dangerous</i>
|
|
@@ -11,9 +20,9 @@
|
|
|
11
20
|
<div v-if="!advancedSearch" class="card-search" :class="{ open: searchBarOpen }">
|
|
12
21
|
<div class="form-group label-floating is-empty">
|
|
13
22
|
<i class="material-icons search-icon-left">search</i>
|
|
14
|
-
<input type="text" class="form-control filter-input" placeholder="
|
|
23
|
+
<input type="text" class="form-control filter-input" :placeholder="t('search')" autocomplete="off"
|
|
15
24
|
@keyup="setSearchTerm">
|
|
16
|
-
<a href="javascript:void(0)" class="close-search" @click="clearSearch" data-tippy-content="
|
|
25
|
+
<a href="javascript:void(0)" class="close-search" @click="clearSearch" :data-tippy-content="t('close')">
|
|
17
26
|
<i class="material-icons">close</i>
|
|
18
27
|
</a>
|
|
19
28
|
</div>
|
|
@@ -21,16 +30,16 @@
|
|
|
21
30
|
<ul class="card-actions icons right-top">
|
|
22
31
|
<slot name="actions"></slot>
|
|
23
32
|
<li v-if="createLink">
|
|
24
|
-
<Link :href="createLink" data-tippy-content="
|
|
33
|
+
<Link :href="createLink" :data-tippy-content="t('createNew')">
|
|
25
34
|
<i class="material-icons">add</i>
|
|
26
35
|
</Link>
|
|
27
36
|
</li>
|
|
28
37
|
<li>
|
|
29
|
-
<a href="javascript:void(0)" data-tippy-content="
|
|
38
|
+
<a href="javascript:void(0)" :data-tippy-content="t('search')" @click="toggleSearch">
|
|
30
39
|
<i class="material-icons">search</i>
|
|
31
40
|
</a>
|
|
32
41
|
</li>
|
|
33
|
-
<li class="dropdown" data-tippy-content="
|
|
42
|
+
<li class="dropdown" :data-tippy-content="t('showEntries')">
|
|
34
43
|
<a href="javascript:void(0)" data-bs-toggle="dropdown">
|
|
35
44
|
<i class="material-icons">more_vert</i>
|
|
36
45
|
</a>
|
|
@@ -55,13 +64,19 @@
|
|
|
55
64
|
<slot name="default"></slot>
|
|
56
65
|
<div v-if="advancedSearch" class="toolbar" :class="{ open: searchBarOpen }">
|
|
57
66
|
<form @submit.prevent="setAdvancedSearchFilters">
|
|
58
|
-
<template
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
<template
|
|
68
|
+
v-for="(column, index) in columns"
|
|
69
|
+
:key="index"
|
|
70
|
+
>
|
|
71
|
+
<span v-if="column.searchable !== false" class="bmd-form-group">
|
|
72
|
+
<input
|
|
73
|
+
:name="column.name"
|
|
74
|
+
class="form-control advanced-filter-input"
|
|
75
|
+
:placeholder="column.displayName" autocomplete="off"
|
|
76
|
+
/>
|
|
62
77
|
</span>
|
|
63
78
|
</template>
|
|
64
|
-
<button type="submit" class="btn btn-primary">
|
|
79
|
+
<button type="submit" class="btn btn-primary">{{ t('search') }}</button>
|
|
65
80
|
</form>
|
|
66
81
|
</div>
|
|
67
82
|
<div class="table-responsive">
|
|
@@ -81,7 +96,7 @@
|
|
|
81
96
|
{{ column.displayName }}
|
|
82
97
|
</th>
|
|
83
98
|
</template>
|
|
84
|
-
<th v-if="actions" class="w-25">
|
|
99
|
+
<th v-if="actions?.length" class="w-25">{{ t('actions') }}</th>
|
|
85
100
|
</tr>
|
|
86
101
|
</thead>
|
|
87
102
|
<tbody>
|
|
@@ -91,26 +106,50 @@
|
|
|
91
106
|
@click="clickableRows ? $emit('row-click', row) : null"
|
|
92
107
|
>
|
|
93
108
|
<td v-if="selectableRows">
|
|
94
|
-
<input
|
|
109
|
+
<input
|
|
110
|
+
type="checkbox"
|
|
111
|
+
:value="row.id"
|
|
112
|
+
v-model="selectedRows"
|
|
113
|
+
@click.stop
|
|
114
|
+
>
|
|
95
115
|
</td>
|
|
96
116
|
<template v-for="(column, index) in columns" :key="index">
|
|
97
117
|
<td
|
|
98
118
|
v-if="column.visible !== false"
|
|
99
119
|
:class="getCellClasses(column, row)"
|
|
100
120
|
>
|
|
101
|
-
<
|
|
102
|
-
v-html="
|
|
121
|
+
<template v-if="column.render">
|
|
122
|
+
<span v-html="column.render(row)"></span>
|
|
123
|
+
</template>
|
|
124
|
+
<Link
|
|
125
|
+
v-else-if="column.link && hyperlinkStyle === 'Link'"
|
|
126
|
+
:href="column.link(row)"
|
|
127
|
+
@click.stop
|
|
128
|
+
>
|
|
129
|
+
{{row[column.data]}}
|
|
103
130
|
</Link>
|
|
104
|
-
<a
|
|
105
|
-
v-
|
|
131
|
+
<a
|
|
132
|
+
v-else-if="column.link && hyperlinkStyle === 'a'"
|
|
133
|
+
:href="column.link(row)"
|
|
134
|
+
@click.stop
|
|
135
|
+
>
|
|
136
|
+
{{row[column.data]}}
|
|
137
|
+
</a>
|
|
106
138
|
<template v-else>
|
|
107
|
-
<span
|
|
139
|
+
<span>
|
|
140
|
+
{{row[column.data]}}
|
|
141
|
+
</span>
|
|
108
142
|
</template>
|
|
109
143
|
</td>
|
|
110
144
|
</template>
|
|
111
|
-
<td v-if="actions">
|
|
112
|
-
<button
|
|
113
|
-
|
|
145
|
+
<td v-if="actions?.length">
|
|
146
|
+
<button
|
|
147
|
+
v-for="(action, index) in actions"
|
|
148
|
+
:key="index"
|
|
149
|
+
class="btn btn-sm"
|
|
150
|
+
:class="action.class"
|
|
151
|
+
@click.stop="handleEmit(action.emit, row)"
|
|
152
|
+
>
|
|
114
153
|
<i v-if="action.icon" class="material-icons">{{ action.icon }}</i> {{
|
|
115
154
|
action.label
|
|
116
155
|
}}
|
|
@@ -121,26 +160,44 @@
|
|
|
121
160
|
</table>
|
|
122
161
|
<div class="d-flex justify-content-between align-items-center mt-3">
|
|
123
162
|
<div class="dataTables_info">
|
|
124
|
-
|
|
163
|
+
{{
|
|
164
|
+
t('showingRecords', {
|
|
165
|
+
first: firstRecord,
|
|
166
|
+
last: lastRecord,
|
|
167
|
+
filtered: recordsFiltered,
|
|
168
|
+
})
|
|
169
|
+
}}
|
|
125
170
|
<span v-if="recordsFiltered != recordsTotal">
|
|
126
|
-
(
|
|
171
|
+
({{
|
|
172
|
+
t('totalRecords', {
|
|
173
|
+
total: recordsTotal,
|
|
174
|
+
})
|
|
175
|
+
}})
|
|
127
176
|
</span>
|
|
128
177
|
</div>
|
|
129
178
|
<div class="dataTables_paginate paging_simple_numbers user-select-none"
|
|
130
179
|
id="document-index-table_paginate">
|
|
131
|
-
<a
|
|
132
|
-
|
|
180
|
+
<a
|
|
181
|
+
class="paginate_button first user-select-none"
|
|
182
|
+
:class="{ disabled: columnSettings.start == 0 }"
|
|
183
|
+
@click="setPage(1)"
|
|
184
|
+
>{{ t('first') }}</a>
|
|
133
185
|
<a class="paginate_button previous" :class="{ disabled: columnSettings.start == 0 }"
|
|
134
|
-
@click="setPage(currentPage - 1)">
|
|
186
|
+
@click="setPage(currentPage - 1)">{{ t('previous') }}</a>
|
|
135
187
|
|
|
136
188
|
<span>
|
|
137
|
-
<a
|
|
138
|
-
|
|
189
|
+
<a
|
|
190
|
+
v-for="(page, index) in pages"
|
|
191
|
+
:key="index"
|
|
192
|
+
class="paginate_button"
|
|
193
|
+
:class="{ current: page == currentPage }"
|
|
194
|
+
@click="setPage(page)"
|
|
195
|
+
>{{ page }}</a>
|
|
139
196
|
</span>
|
|
140
197
|
<a class="paginate_button next" :class="{ disabled: columnSettings.start >= lastPageStart }"
|
|
141
|
-
@click="setPage(currentPage + 1)">
|
|
198
|
+
@click="setPage(currentPage + 1)">{{ t('next') }}</a>
|
|
142
199
|
<a class="paginate_button last" :class="{ disabled: columnSettings.start >= lastPageStart }"
|
|
143
|
-
@click="setPage(pageCount)">
|
|
200
|
+
@click="setPage(pageCount)">{{ t('last') }}</a>
|
|
144
201
|
</div>
|
|
145
202
|
</div>
|
|
146
203
|
</div>
|
|
@@ -152,6 +209,7 @@
|
|
|
152
209
|
<script>
|
|
153
210
|
import axios from 'axios';
|
|
154
211
|
import { Link } from '@inertiajs/vue3';
|
|
212
|
+
import { defaultVocabulary } from '../locales';
|
|
155
213
|
|
|
156
214
|
export default {
|
|
157
215
|
name: "DatatableCard",
|
|
@@ -159,6 +217,18 @@ export default {
|
|
|
159
217
|
Link,
|
|
160
218
|
},
|
|
161
219
|
props: {
|
|
220
|
+
locale: {
|
|
221
|
+
type: String,
|
|
222
|
+
required: false,
|
|
223
|
+
default: 'en',
|
|
224
|
+
},
|
|
225
|
+
vocabulary: {
|
|
226
|
+
type: Object,
|
|
227
|
+
required: false,
|
|
228
|
+
default: () => {
|
|
229
|
+
return {};
|
|
230
|
+
}
|
|
231
|
+
},
|
|
162
232
|
cardTitle: {
|
|
163
233
|
type: String,
|
|
164
234
|
required: false,
|
|
@@ -200,7 +270,7 @@ export default {
|
|
|
200
270
|
order: {
|
|
201
271
|
type: Array,
|
|
202
272
|
required: false,
|
|
203
|
-
default: [
|
|
273
|
+
default: () => [
|
|
204
274
|
{
|
|
205
275
|
column: 0,
|
|
206
276
|
dir: 'asc',
|
|
@@ -239,6 +309,11 @@ export default {
|
|
|
239
309
|
required: false,
|
|
240
310
|
default: 'Link',
|
|
241
311
|
},
|
|
312
|
+
pageLength: {
|
|
313
|
+
type: Number,
|
|
314
|
+
required: false,
|
|
315
|
+
default: 10,
|
|
316
|
+
},
|
|
242
317
|
},
|
|
243
318
|
emits: ['row-click'],
|
|
244
319
|
data() {
|
|
@@ -251,6 +326,7 @@ export default {
|
|
|
251
326
|
recordsFiltered: 0,
|
|
252
327
|
selectedRows: [],
|
|
253
328
|
cardError: null,
|
|
329
|
+
searchTimer: null,
|
|
254
330
|
}
|
|
255
331
|
},
|
|
256
332
|
watch: {
|
|
@@ -272,7 +348,9 @@ export default {
|
|
|
272
348
|
},
|
|
273
349
|
computed: {
|
|
274
350
|
firstRecord() {
|
|
275
|
-
return this.
|
|
351
|
+
return this.recordsFiltered === 0
|
|
352
|
+
? 0
|
|
353
|
+
: this.columnSettings.start + 1;
|
|
276
354
|
},
|
|
277
355
|
lastRecord() {
|
|
278
356
|
return this.columnSettings.start + this.rows.length;
|
|
@@ -415,18 +493,35 @@ export default {
|
|
|
415
493
|
}
|
|
416
494
|
},
|
|
417
495
|
clearSearch() {
|
|
496
|
+
clearTimeout(this.searchTimer);
|
|
497
|
+
|
|
418
498
|
this.searchBarOpen = false;
|
|
419
|
-
this.$el.querySelector('.filter-input').value = '';
|
|
420
|
-
this.columnSettings.search.value = '';
|
|
421
499
|
|
|
500
|
+
const input = this.$el.querySelector('.filter-input');
|
|
501
|
+
|
|
502
|
+
if (input) {
|
|
503
|
+
input.value = '';
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
this.columnSettings.search.value = '';
|
|
507
|
+
this.columnSettings.start = 0;
|
|
422
508
|
this.loadData();
|
|
423
509
|
},
|
|
424
510
|
setAdvancedSearchFilters() {
|
|
425
|
-
this.columnSettings.
|
|
426
|
-
|
|
427
|
-
|
|
511
|
+
this.columnSettings.start = 0;
|
|
512
|
+
|
|
513
|
+
this.columnSettings.columns.forEach(column => {
|
|
514
|
+
if (!column.searchable) {
|
|
515
|
+
return;
|
|
428
516
|
}
|
|
517
|
+
|
|
518
|
+
const input = this.$el.querySelector(
|
|
519
|
+
`input[name="${CSS.escape(column.name)}"]`
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
column.search.value = input?.value ?? '';
|
|
429
523
|
});
|
|
524
|
+
|
|
430
525
|
this.loadData();
|
|
431
526
|
},
|
|
432
527
|
loadData() {
|
|
@@ -438,7 +533,7 @@ export default {
|
|
|
438
533
|
};
|
|
439
534
|
axios.get(this.url, { params: params }).then(response => {
|
|
440
535
|
if (response.data.error) {
|
|
441
|
-
this.cardError =
|
|
536
|
+
this.cardError = this.t('loadingError');
|
|
442
537
|
console.error(response.data.error);
|
|
443
538
|
return;
|
|
444
539
|
}
|
|
@@ -449,7 +544,10 @@ export default {
|
|
|
449
544
|
this.recordsFiltered = response.data.recordsFiltered;
|
|
450
545
|
})
|
|
451
546
|
.catch(error => {
|
|
452
|
-
this.cardError =
|
|
547
|
+
this.cardError =
|
|
548
|
+
error.response?.data?.message ??
|
|
549
|
+
this.t('loadingError');
|
|
550
|
+
|
|
453
551
|
console.error(error);
|
|
454
552
|
});
|
|
455
553
|
},
|
|
@@ -470,9 +568,9 @@ export default {
|
|
|
470
568
|
}
|
|
471
569
|
}
|
|
472
570
|
}),
|
|
473
|
-
order: this.order,
|
|
571
|
+
order: this.order.map(item => ({ ...item })),
|
|
474
572
|
start: 0,
|
|
475
|
-
length:
|
|
573
|
+
length: this.pageLength,
|
|
476
574
|
search: {
|
|
477
575
|
value: '',
|
|
478
576
|
regex: false,
|
|
@@ -481,6 +579,7 @@ export default {
|
|
|
481
579
|
},
|
|
482
580
|
setPageLength(length) {
|
|
483
581
|
this.columnSettings.length = length;
|
|
582
|
+
this.columnSettings.start = 0;
|
|
484
583
|
this.loadData();
|
|
485
584
|
},
|
|
486
585
|
setPage(page) {
|
|
@@ -491,16 +590,15 @@ export default {
|
|
|
491
590
|
this.loadData();
|
|
492
591
|
},
|
|
493
592
|
setSearchTerm() {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
593
|
+
clearTimeout(this.searchTimer);
|
|
594
|
+
|
|
595
|
+
this.searchTimer = setTimeout(() => {
|
|
596
|
+
const input = this.$el.querySelector('.filter-input');
|
|
597
|
+
|
|
598
|
+
this.columnSettings.search.value =
|
|
599
|
+
input?.value ?? '';
|
|
600
|
+
|
|
497
601
|
this.columnSettings.start = 0;
|
|
498
|
-
// set search term for each column if searchable
|
|
499
|
-
// this.columnSettings.columns.forEach((column, index) => {
|
|
500
|
-
// if(column.searchable){
|
|
501
|
-
// column.search.value = this.columnSettings.search.value;
|
|
502
|
-
// }
|
|
503
|
-
// });
|
|
504
602
|
this.loadData();
|
|
505
603
|
}, 500);
|
|
506
604
|
},
|
|
@@ -524,66 +622,6 @@ export default {
|
|
|
524
622
|
}
|
|
525
623
|
this.loadData();
|
|
526
624
|
},
|
|
527
|
-
/**
|
|
528
|
-
* Build a link for a cell. Supports either:
|
|
529
|
-
* 1) Laravel route name (via Ziggy `route()`) — provide `{ name, resourceIds?, query? }`
|
|
530
|
-
* 2) Link template string — provide `{ template, params?, query? }` OR pass the template directly as a string.
|
|
531
|
-
*
|
|
532
|
-
* Notes
|
|
533
|
-
* - `resourceIds` is an array of row keys (in order) used for `route(name, [...])`.
|
|
534
|
-
* - `template` supports placeholders like `/users/{id}/posts/{post_id}` or `/users/:id`.
|
|
535
|
-
* - `params` (optional) lets you override/augment values used to interpolate the template.
|
|
536
|
-
* - `query` (optional) is appended as a query string for both modes.
|
|
537
|
-
*/
|
|
538
|
-
generateLink(linkParams, row) {
|
|
539
|
-
// Helper: append query object as `?a=1&b=2`
|
|
540
|
-
const appendQuery = (href, query) => {
|
|
541
|
-
if (!query || typeof query !== 'object') return href;
|
|
542
|
-
const qs = new URLSearchParams(query).toString();
|
|
543
|
-
return qs ? `${href}?${qs}` : href;
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
// Helper: interpolate `{key}` and `:key` tokens from row/params
|
|
547
|
-
const interpolate = (tpl, ctx) => {
|
|
548
|
-
if (!tpl) return '';
|
|
549
|
-
// {key}
|
|
550
|
-
let out = tpl.replace(/\{(\w+)\}/g, (_, k) => (ctx[k] ?? ''));
|
|
551
|
-
// :key (avoid matching protocol like http://)
|
|
552
|
-
out = out.replace(/(^|[^:]):(\w+)/g, (m, prefix, k) => `${prefix}${ctx[k] ?? ''}`);
|
|
553
|
-
return out;
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
// String shorthand => treat as a template
|
|
557
|
-
if (typeof linkParams === 'string') {
|
|
558
|
-
const href = interpolate(linkParams, row);
|
|
559
|
-
return href; // no query in shorthand; use object form if you need query
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// Safety
|
|
563
|
-
if (!linkParams || typeof linkParams !== 'object') return '';
|
|
564
|
-
|
|
565
|
-
// Template mode
|
|
566
|
-
if (linkParams.template) {
|
|
567
|
-
// Merge row first, then allow explicit overrides via params
|
|
568
|
-
const ctx = { ...(row || {}), ...(linkParams.params || {}) };
|
|
569
|
-
const href = interpolate(linkParams.template, ctx);
|
|
570
|
-
return appendQuery(href, linkParams.query);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// Route name mode (default/back-compat)
|
|
574
|
-
if (linkParams.name) {
|
|
575
|
-
const ids = Array.isArray(linkParams.resourceIds)
|
|
576
|
-
? linkParams.resourceIds.map((key) => (row ? row[key] : undefined))
|
|
577
|
-
: [];
|
|
578
|
-
|
|
579
|
-
// `route` comes from Ziggy; assume it is globally available as in your existing codebase
|
|
580
|
-
let href = route(linkParams.name, ids);
|
|
581
|
-
return appendQuery(href, linkParams.query);
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
// Nothing to build
|
|
585
|
-
return '';
|
|
586
|
-
},
|
|
587
625
|
selectAllRows() {
|
|
588
626
|
if (this.selectedRows.length == this.rows.length) {
|
|
589
627
|
this.selectedRows = [];
|
|
@@ -620,15 +658,42 @@ export default {
|
|
|
620
658
|
});
|
|
621
659
|
}
|
|
622
660
|
});
|
|
623
|
-
|
|
661
|
+
|
|
662
|
+
this.columnSettings.start = 0;
|
|
624
663
|
this.loadData();
|
|
625
664
|
},
|
|
626
665
|
getSelectedRows() {
|
|
627
666
|
return this.selectedRows;
|
|
628
667
|
},
|
|
668
|
+
t(key, replacements = {}) {
|
|
669
|
+
const packageLocale =
|
|
670
|
+
defaultVocabulary[this.locale] ??
|
|
671
|
+
defaultVocabulary.en;
|
|
672
|
+
|
|
673
|
+
const customLocale =
|
|
674
|
+
this.vocabulary[this.locale] ??
|
|
675
|
+
this.vocabulary.en;
|
|
676
|
+
|
|
677
|
+
let translation =
|
|
678
|
+
customLocale?.[key] ??
|
|
679
|
+
packageLocale?.[key] ??
|
|
680
|
+
defaultVocabulary.en[key] ??
|
|
681
|
+
key;
|
|
682
|
+
|
|
683
|
+
Object.entries(replacements).forEach(([name, value]) => {
|
|
684
|
+
translation = translation.replaceAll(
|
|
685
|
+
`{${name}}`,
|
|
686
|
+
String(value)
|
|
687
|
+
);
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
return translation;
|
|
691
|
+
},
|
|
629
692
|
},
|
|
630
|
-
|
|
693
|
+
created() {
|
|
631
694
|
this.initColumnSettings();
|
|
695
|
+
},
|
|
696
|
+
mounted() {
|
|
632
697
|
if (this.loadDataOnInit) {
|
|
633
698
|
this.loadData();
|
|
634
699
|
}
|
package/src/locales.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/locales.js
|
|
2
|
+
|
|
3
|
+
export const defaultVocabulary = {
|
|
4
|
+
en: {
|
|
5
|
+
search: 'Search',
|
|
6
|
+
close: 'Close',
|
|
7
|
+
createNew: 'Create new',
|
|
8
|
+
showEntries: 'Show entries',
|
|
9
|
+
actions: 'Actions',
|
|
10
|
+
first: 'First',
|
|
11
|
+
previous: 'Previous',
|
|
12
|
+
next: 'Next',
|
|
13
|
+
last: 'Last',
|
|
14
|
+
showingRecords: 'Showing {first} to {last} of {filtered} records',
|
|
15
|
+
totalRecords: '{total} records in total',
|
|
16
|
+
loadingError: 'Error loading data. See console for details.',
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
lv: {
|
|
20
|
+
search: 'Meklēt',
|
|
21
|
+
close: 'Aizvērt',
|
|
22
|
+
createNew: 'Izveidot jaunu',
|
|
23
|
+
showEntries: 'Rādīt ierakstus',
|
|
24
|
+
actions: 'Darbības',
|
|
25
|
+
first: 'Pirmā',
|
|
26
|
+
previous: 'Iepriekšējā',
|
|
27
|
+
next: 'Nākamā',
|
|
28
|
+
last: 'Pēdējā',
|
|
29
|
+
showingRecords: 'Rāda {first}. līdz {last}. no {filtered} ierakstiem',
|
|
30
|
+
totalRecords: 'kopā {total} ieraksti',
|
|
31
|
+
loadingError: 'Kļūda, ielādējot datus. Sīkāku informāciju par kļūdu skaties konsolē.',
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
ru: {
|
|
35
|
+
search: 'Поиск',
|
|
36
|
+
close: 'Закрыть',
|
|
37
|
+
createNew: 'Создать',
|
|
38
|
+
showEntries: 'Показать записи',
|
|
39
|
+
actions: 'Действия',
|
|
40
|
+
first: 'Первая',
|
|
41
|
+
previous: 'Предыдущая',
|
|
42
|
+
next: 'Следующая',
|
|
43
|
+
last: 'Последняя',
|
|
44
|
+
showingRecords: 'Показаны записи с {first} по {last} из {filtered}',
|
|
45
|
+
totalRecords: 'всего {total} записей',
|
|
46
|
+
loadingError: 'Ошибка загрузки данных. См. консоль для подробностей.',
|
|
47
|
+
},
|
|
48
|
+
};
|