@sulzanoks/vue-datatable 0.3.6 → 0.4.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 +480 -132
- package/dist/datatable-card.es.js +2011 -1938
- package/dist/datatable-card.umd.js +7 -7
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/Components/DatatableCard.vue +223 -154
- package/src/locales.js +48 -0
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.toolbar[data-v-
|
|
1
|
+
.toolbar[data-v-d524144f]:not(.open){display:none}.card .card-heading[data-v-d524144f]{padding:15px 20px;position:relative;height:65px}.card .card-search[data-v-d524144f]{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-d524144f]{margin:0;padding:0;height:65px}.card .card-search .search-icon-left[data-v-d524144f]{left:15px;right:auto}.card .card-search .close-search[data-v-d524144f],.card .card-search .search-icon-left[data-v-d524144f]{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-d524144f]{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-d524144f]{right:15px;left:auto}.card .card-search .search-icon-left[data-v-d524144f]{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-d524144f]{display:block}.card-heading ul.card-actions.icons[data-v-d524144f]{position:absolute;list-style:none;padding:0;margin:0}ul.card-actions.icons li[data-v-d524144f]{display:inline}.dataTables_wrapper .dataTables_paginate .paginate_button.current[data-v-d524144f],.dataTables_wrapper .dataTables_paginate .paginate_button.current[data-v-d524144f]: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-d524144f],.dataTables_wrapper .dataTables_paginate .paginate_button[data-v-d524144f]: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-d524144f]:hover{border:1}.card-header[data-v-d524144f]:first-child{border-radius:calc(.25rem - 1px) calc(.25rem - 1px) 0 0}.card .card-header[data-v-d524144f]{border-bottom:none;background:transparent}.card [class*=card-header-][data-v-d524144f],.card[class*=bg-][data-v-d524144f]{color:#fff}.card .card-header[data-v-d524144f]{z-index:3!important}.card [class*=card-header-][data-v-d524144f]{margin:0 15px;padding:0;position:relative}.card [class*=card-header-] .card-icon[data-v-d524144f],.card [class*=card-header-] .card-text[data-v-d524144f]{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-d524144f],.card .card-header.card-header-text i[data-v-d524144f]{width:33px;height:33px;text-align:center;line-height:33px}.card[data-v-d524144f]{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-d524144f],.card .card-header.card-header-text .card-title[data-v-d524144f]{margin-top:15px;color:#3c4858}.card .card-header.card-header-icon h4[data-v-d524144f],.card .card-header.card-header-text h4[data-v-d524144f]{font-weight:300}.card .card-header .card-title[data-v-d524144f]{margin-bottom:3px}.card .card-actions[data-v-d524144f]{position:absolute;z-index:1;top:-50px;width:calc(100% - 30px);left:17px;right:17px;text-align:center}.card .card-actions[data-v-d524144f]{text-align:end}.card ul.card-actions.icons[data-v-d524144f]{position:absolute;list-style:none;padding:0;margin:0;right:10px;top:15px}ul.card-actions.icons.right-top[data-v-d524144f]{right:10px;top:15px}ul.card-actions.icons li[data-v-d524144f]{display:inline;width:100%;text-align:unset}.dropdown-menu .dropdown-item[data-v-d524144f],.dropdown-menu li>a[data-v-d524144f]{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-d524144f],.dropdown-menu li>a[data-v-d524144f]{padding-right:1.5rem;padding-left:1.5rem}.dropdown-menu[data-v-d524144f]{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-d524144f]{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-d524144f]{margin:0!important}.clickable-rows tbody tr[data-v-d524144f]{cursor:pointer}
|
package/package.json
CHANGED
|
@@ -1,67 +1,86 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="card" :class="cardClasses">
|
|
3
|
-
<header
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
</
|
|
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>
|
|
14
|
+
<template
|
|
15
|
+
v-if="showHeader"
|
|
16
|
+
>
|
|
17
|
+
<div v-if="cardIcon" class="card-icon">
|
|
18
|
+
<i v-if="!cardError" class="material-icons">{{ cardIcon }}</i>
|
|
19
|
+
<i v-else class="material-icons">dangerous</i>
|
|
19
20
|
</div>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
21
|
+
<h4 v-if="cardTitle && !cardError" class="card-title">{{ cardTitle }}</h4>
|
|
22
|
+
<h4 v-if="cardError" class="card-title text-danger">{{ cardError }}</h4>
|
|
23
|
+
<div v-if="!advancedSearch" class="card-search" :class="{ open: searchBarOpen }">
|
|
24
|
+
<div class="form-group label-floating is-empty">
|
|
25
|
+
<i class="material-icons search-icon-left">search</i>
|
|
26
|
+
<input type="text" class="form-control filter-input" :placeholder="t('search')" autocomplete="off"
|
|
27
|
+
@keyup="setSearchTerm">
|
|
28
|
+
<a href="javascript:void(0)" class="close-search" @click="clearSearch" :data-tippy-content="t('close')">
|
|
29
|
+
<i class="material-icons">close</i>
|
|
30
|
+
</a>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
<ul class="card-actions icons right-top">
|
|
34
|
+
<slot name="actions"></slot>
|
|
35
|
+
<li v-if="createLink">
|
|
36
|
+
<Link :href="createLink" :data-tippy-content="t('createNew')">
|
|
37
|
+
<i class="material-icons">add</i>
|
|
38
|
+
</Link>
|
|
39
|
+
</li>
|
|
40
|
+
<li>
|
|
41
|
+
<a href="javascript:void(0)" :data-tippy-content="t('search')" @click="toggleSearch">
|
|
42
|
+
<i class="material-icons">search</i>
|
|
43
|
+
</a>
|
|
44
|
+
</li>
|
|
45
|
+
<li class="dropdown" :data-tippy-content="t('showEntries')">
|
|
46
|
+
<a href="javascript:void(0)" data-bs-toggle="dropdown">
|
|
47
|
+
<i class="material-icons">more_vert</i>
|
|
48
|
+
</a>
|
|
49
|
+
<ul class="dropdown-menu dropdown-menu-right">
|
|
50
|
+
<li @click="setPageLength(10)">
|
|
51
|
+
<a href="javascript:void(0)">10</a>
|
|
52
|
+
</li>
|
|
53
|
+
<li @click="setPageLength(25)">
|
|
54
|
+
<a href="javascript:void(0)">25</a>
|
|
55
|
+
</li>
|
|
56
|
+
<li @click="setPageLength(50)">
|
|
57
|
+
<a href="javascript:void(0)">50</a>
|
|
58
|
+
</li>
|
|
59
|
+
<li @click="setPageLength(100)">
|
|
60
|
+
<a href="javascript:void(0)">100</a>
|
|
61
|
+
</li>
|
|
62
|
+
</ul>
|
|
63
|
+
</li>
|
|
64
|
+
</ul>
|
|
65
|
+
</template>
|
|
53
66
|
</header>
|
|
54
67
|
<div class="card-body">
|
|
55
68
|
<slot name="default"></slot>
|
|
56
69
|
<div v-if="advancedSearch" class="toolbar" :class="{ open: searchBarOpen }">
|
|
57
70
|
<form @submit.prevent="setAdvancedSearchFilters">
|
|
58
|
-
<template
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
<template
|
|
72
|
+
v-for="(column, index) in columns"
|
|
73
|
+
:key="index"
|
|
74
|
+
>
|
|
75
|
+
<span v-if="column.searchable !== false" class="bmd-form-group">
|
|
76
|
+
<input
|
|
77
|
+
:name="column.name"
|
|
78
|
+
class="form-control advanced-filter-input"
|
|
79
|
+
:placeholder="column.displayName" autocomplete="off"
|
|
80
|
+
/>
|
|
62
81
|
</span>
|
|
63
82
|
</template>
|
|
64
|
-
<button type="submit" class="btn btn-primary">
|
|
83
|
+
<button type="submit" class="btn btn-primary">{{ t('search') }}</button>
|
|
65
84
|
</form>
|
|
66
85
|
</div>
|
|
67
86
|
<div class="table-responsive">
|
|
@@ -81,7 +100,7 @@
|
|
|
81
100
|
{{ column.displayName }}
|
|
82
101
|
</th>
|
|
83
102
|
</template>
|
|
84
|
-
<th v-if="actions" class="w-25">
|
|
103
|
+
<th v-if="actions?.length" class="w-25">{{ t('actions') }}</th>
|
|
85
104
|
</tr>
|
|
86
105
|
</thead>
|
|
87
106
|
<tbody>
|
|
@@ -91,26 +110,50 @@
|
|
|
91
110
|
@click="clickableRows ? $emit('row-click', row) : null"
|
|
92
111
|
>
|
|
93
112
|
<td v-if="selectableRows">
|
|
94
|
-
<input
|
|
113
|
+
<input
|
|
114
|
+
type="checkbox"
|
|
115
|
+
:value="row.id"
|
|
116
|
+
v-model="selectedRows"
|
|
117
|
+
@click.stop
|
|
118
|
+
>
|
|
95
119
|
</td>
|
|
96
120
|
<template v-for="(column, index) in columns" :key="index">
|
|
97
121
|
<td
|
|
98
122
|
v-if="column.visible !== false"
|
|
99
123
|
:class="getCellClasses(column, row)"
|
|
100
124
|
>
|
|
101
|
-
<
|
|
102
|
-
v-html="
|
|
125
|
+
<template v-if="column.render">
|
|
126
|
+
<span v-html="column.render(row)"></span>
|
|
127
|
+
</template>
|
|
128
|
+
<Link
|
|
129
|
+
v-else-if="column.link && hyperlinkStyle === 'Link'"
|
|
130
|
+
:href="column.link(row)"
|
|
131
|
+
@click.stop
|
|
132
|
+
>
|
|
133
|
+
{{row[column.data]}}
|
|
103
134
|
</Link>
|
|
104
|
-
<a
|
|
105
|
-
v-
|
|
135
|
+
<a
|
|
136
|
+
v-else-if="column.link && hyperlinkStyle === 'a'"
|
|
137
|
+
:href="column.link(row)"
|
|
138
|
+
@click.stop
|
|
139
|
+
>
|
|
140
|
+
{{row[column.data]}}
|
|
141
|
+
</a>
|
|
106
142
|
<template v-else>
|
|
107
|
-
<span
|
|
143
|
+
<span>
|
|
144
|
+
{{row[column.data]}}
|
|
145
|
+
</span>
|
|
108
146
|
</template>
|
|
109
147
|
</td>
|
|
110
148
|
</template>
|
|
111
|
-
<td v-if="actions">
|
|
112
|
-
<button
|
|
113
|
-
|
|
149
|
+
<td v-if="actions?.length">
|
|
150
|
+
<button
|
|
151
|
+
v-for="(action, index) in actions"
|
|
152
|
+
:key="index"
|
|
153
|
+
class="btn btn-sm"
|
|
154
|
+
:class="action.class"
|
|
155
|
+
@click.stop="handleEmit(action.emit, row)"
|
|
156
|
+
>
|
|
114
157
|
<i v-if="action.icon" class="material-icons">{{ action.icon }}</i> {{
|
|
115
158
|
action.label
|
|
116
159
|
}}
|
|
@@ -121,26 +164,44 @@
|
|
|
121
164
|
</table>
|
|
122
165
|
<div class="d-flex justify-content-between align-items-center mt-3">
|
|
123
166
|
<div class="dataTables_info">
|
|
124
|
-
|
|
167
|
+
{{
|
|
168
|
+
t('showingRecords', {
|
|
169
|
+
first: firstRecord,
|
|
170
|
+
last: lastRecord,
|
|
171
|
+
filtered: recordsFiltered,
|
|
172
|
+
})
|
|
173
|
+
}}
|
|
125
174
|
<span v-if="recordsFiltered != recordsTotal">
|
|
126
|
-
(
|
|
175
|
+
({{
|
|
176
|
+
t('totalRecords', {
|
|
177
|
+
total: recordsTotal,
|
|
178
|
+
})
|
|
179
|
+
}})
|
|
127
180
|
</span>
|
|
128
181
|
</div>
|
|
129
182
|
<div class="dataTables_paginate paging_simple_numbers user-select-none"
|
|
130
183
|
id="document-index-table_paginate">
|
|
131
|
-
<a
|
|
132
|
-
|
|
184
|
+
<a
|
|
185
|
+
class="paginate_button first user-select-none"
|
|
186
|
+
:class="{ disabled: columnSettings.start == 0 }"
|
|
187
|
+
@click="setPage(1)"
|
|
188
|
+
>{{ t('first') }}</a>
|
|
133
189
|
<a class="paginate_button previous" :class="{ disabled: columnSettings.start == 0 }"
|
|
134
|
-
@click="setPage(currentPage - 1)">
|
|
190
|
+
@click="setPage(currentPage - 1)">{{ t('previous') }}</a>
|
|
135
191
|
|
|
136
192
|
<span>
|
|
137
|
-
<a
|
|
138
|
-
|
|
193
|
+
<a
|
|
194
|
+
v-for="(page, index) in pages"
|
|
195
|
+
:key="index"
|
|
196
|
+
class="paginate_button"
|
|
197
|
+
:class="{ current: page == currentPage }"
|
|
198
|
+
@click="setPage(page)"
|
|
199
|
+
>{{ page }}</a>
|
|
139
200
|
</span>
|
|
140
201
|
<a class="paginate_button next" :class="{ disabled: columnSettings.start >= lastPageStart }"
|
|
141
|
-
@click="setPage(currentPage + 1)">
|
|
202
|
+
@click="setPage(currentPage + 1)">{{ t('next') }}</a>
|
|
142
203
|
<a class="paginate_button last" :class="{ disabled: columnSettings.start >= lastPageStart }"
|
|
143
|
-
@click="setPage(pageCount)">
|
|
204
|
+
@click="setPage(pageCount)">{{ t('last') }}</a>
|
|
144
205
|
</div>
|
|
145
206
|
</div>
|
|
146
207
|
</div>
|
|
@@ -152,6 +213,7 @@
|
|
|
152
213
|
<script>
|
|
153
214
|
import axios from 'axios';
|
|
154
215
|
import { Link } from '@inertiajs/vue3';
|
|
216
|
+
import { defaultVocabulary } from '../locales';
|
|
155
217
|
|
|
156
218
|
export default {
|
|
157
219
|
name: "DatatableCard",
|
|
@@ -159,6 +221,18 @@ export default {
|
|
|
159
221
|
Link,
|
|
160
222
|
},
|
|
161
223
|
props: {
|
|
224
|
+
locale: {
|
|
225
|
+
type: String,
|
|
226
|
+
required: false,
|
|
227
|
+
default: 'en',
|
|
228
|
+
},
|
|
229
|
+
vocabulary: {
|
|
230
|
+
type: Object,
|
|
231
|
+
required: false,
|
|
232
|
+
default: () => {
|
|
233
|
+
return {};
|
|
234
|
+
}
|
|
235
|
+
},
|
|
162
236
|
cardTitle: {
|
|
163
237
|
type: String,
|
|
164
238
|
required: false,
|
|
@@ -200,7 +274,7 @@ export default {
|
|
|
200
274
|
order: {
|
|
201
275
|
type: Array,
|
|
202
276
|
required: false,
|
|
203
|
-
default: [
|
|
277
|
+
default: () => [
|
|
204
278
|
{
|
|
205
279
|
column: 0,
|
|
206
280
|
dir: 'asc',
|
|
@@ -244,6 +318,11 @@ export default {
|
|
|
244
318
|
required: false,
|
|
245
319
|
default: 10,
|
|
246
320
|
},
|
|
321
|
+
showHeader: {
|
|
322
|
+
type: Boolean,
|
|
323
|
+
required: false,
|
|
324
|
+
default: true,
|
|
325
|
+
},
|
|
247
326
|
},
|
|
248
327
|
emits: ['row-click'],
|
|
249
328
|
data() {
|
|
@@ -256,6 +335,7 @@ export default {
|
|
|
256
335
|
recordsFiltered: 0,
|
|
257
336
|
selectedRows: [],
|
|
258
337
|
cardError: null,
|
|
338
|
+
searchTimer: null,
|
|
259
339
|
}
|
|
260
340
|
},
|
|
261
341
|
watch: {
|
|
@@ -277,7 +357,9 @@ export default {
|
|
|
277
357
|
},
|
|
278
358
|
computed: {
|
|
279
359
|
firstRecord() {
|
|
280
|
-
return this.
|
|
360
|
+
return this.recordsFiltered === 0
|
|
361
|
+
? 0
|
|
362
|
+
: this.columnSettings.start + 1;
|
|
281
363
|
},
|
|
282
364
|
lastRecord() {
|
|
283
365
|
return this.columnSettings.start + this.rows.length;
|
|
@@ -420,18 +502,35 @@ export default {
|
|
|
420
502
|
}
|
|
421
503
|
},
|
|
422
504
|
clearSearch() {
|
|
505
|
+
clearTimeout(this.searchTimer);
|
|
506
|
+
|
|
423
507
|
this.searchBarOpen = false;
|
|
424
|
-
this.$el.querySelector('.filter-input').value = '';
|
|
425
|
-
this.columnSettings.search.value = '';
|
|
426
508
|
|
|
509
|
+
const input = this.$el.querySelector('.filter-input');
|
|
510
|
+
|
|
511
|
+
if (input) {
|
|
512
|
+
input.value = '';
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
this.columnSettings.search.value = '';
|
|
516
|
+
this.columnSettings.start = 0;
|
|
427
517
|
this.loadData();
|
|
428
518
|
},
|
|
429
519
|
setAdvancedSearchFilters() {
|
|
430
|
-
this.columnSettings.
|
|
431
|
-
|
|
432
|
-
|
|
520
|
+
this.columnSettings.start = 0;
|
|
521
|
+
|
|
522
|
+
this.columnSettings.columns.forEach(column => {
|
|
523
|
+
if (!column.searchable) {
|
|
524
|
+
return;
|
|
433
525
|
}
|
|
526
|
+
|
|
527
|
+
const input = this.$el.querySelector(
|
|
528
|
+
`input[name="${CSS.escape(column.name)}"]`
|
|
529
|
+
);
|
|
530
|
+
|
|
531
|
+
column.search.value = input?.value ?? '';
|
|
434
532
|
});
|
|
533
|
+
|
|
435
534
|
this.loadData();
|
|
436
535
|
},
|
|
437
536
|
loadData() {
|
|
@@ -443,7 +542,7 @@ export default {
|
|
|
443
542
|
};
|
|
444
543
|
axios.get(this.url, { params: params }).then(response => {
|
|
445
544
|
if (response.data.error) {
|
|
446
|
-
this.cardError =
|
|
545
|
+
this.cardError = this.t('loadingError');
|
|
447
546
|
console.error(response.data.error);
|
|
448
547
|
return;
|
|
449
548
|
}
|
|
@@ -454,7 +553,10 @@ export default {
|
|
|
454
553
|
this.recordsFiltered = response.data.recordsFiltered;
|
|
455
554
|
})
|
|
456
555
|
.catch(error => {
|
|
457
|
-
this.cardError =
|
|
556
|
+
this.cardError =
|
|
557
|
+
error.response?.data?.message ??
|
|
558
|
+
this.t('loadingError');
|
|
559
|
+
|
|
458
560
|
console.error(error);
|
|
459
561
|
});
|
|
460
562
|
},
|
|
@@ -475,7 +577,7 @@ export default {
|
|
|
475
577
|
}
|
|
476
578
|
}
|
|
477
579
|
}),
|
|
478
|
-
order: this.order,
|
|
580
|
+
order: this.order.map(item => ({ ...item })),
|
|
479
581
|
start: 0,
|
|
480
582
|
length: this.pageLength,
|
|
481
583
|
search: {
|
|
@@ -486,6 +588,7 @@ export default {
|
|
|
486
588
|
},
|
|
487
589
|
setPageLength(length) {
|
|
488
590
|
this.columnSettings.length = length;
|
|
591
|
+
this.columnSettings.start = 0;
|
|
489
592
|
this.loadData();
|
|
490
593
|
},
|
|
491
594
|
setPage(page) {
|
|
@@ -496,16 +599,15 @@ export default {
|
|
|
496
599
|
this.loadData();
|
|
497
600
|
},
|
|
498
601
|
setSearchTerm() {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
602
|
+
clearTimeout(this.searchTimer);
|
|
603
|
+
|
|
604
|
+
this.searchTimer = setTimeout(() => {
|
|
605
|
+
const input = this.$el.querySelector('.filter-input');
|
|
606
|
+
|
|
607
|
+
this.columnSettings.search.value =
|
|
608
|
+
input?.value ?? '';
|
|
609
|
+
|
|
502
610
|
this.columnSettings.start = 0;
|
|
503
|
-
// set search term for each column if searchable
|
|
504
|
-
// this.columnSettings.columns.forEach((column, index) => {
|
|
505
|
-
// if(column.searchable){
|
|
506
|
-
// column.search.value = this.columnSettings.search.value;
|
|
507
|
-
// }
|
|
508
|
-
// });
|
|
509
611
|
this.loadData();
|
|
510
612
|
}, 500);
|
|
511
613
|
},
|
|
@@ -529,66 +631,6 @@ export default {
|
|
|
529
631
|
}
|
|
530
632
|
this.loadData();
|
|
531
633
|
},
|
|
532
|
-
/**
|
|
533
|
-
* Build a link for a cell. Supports either:
|
|
534
|
-
* 1) Laravel route name (via Ziggy `route()`) — provide `{ name, resourceIds?, query? }`
|
|
535
|
-
* 2) Link template string — provide `{ template, params?, query? }` OR pass the template directly as a string.
|
|
536
|
-
*
|
|
537
|
-
* Notes
|
|
538
|
-
* - `resourceIds` is an array of row keys (in order) used for `route(name, [...])`.
|
|
539
|
-
* - `template` supports placeholders like `/users/{id}/posts/{post_id}` or `/users/:id`.
|
|
540
|
-
* - `params` (optional) lets you override/augment values used to interpolate the template.
|
|
541
|
-
* - `query` (optional) is appended as a query string for both modes.
|
|
542
|
-
*/
|
|
543
|
-
generateLink(linkParams, row) {
|
|
544
|
-
// Helper: append query object as `?a=1&b=2`
|
|
545
|
-
const appendQuery = (href, query) => {
|
|
546
|
-
if (!query || typeof query !== 'object') return href;
|
|
547
|
-
const qs = new URLSearchParams(query).toString();
|
|
548
|
-
return qs ? `${href}?${qs}` : href;
|
|
549
|
-
};
|
|
550
|
-
|
|
551
|
-
// Helper: interpolate `{key}` and `:key` tokens from row/params
|
|
552
|
-
const interpolate = (tpl, ctx) => {
|
|
553
|
-
if (!tpl) return '';
|
|
554
|
-
// {key}
|
|
555
|
-
let out = tpl.replace(/\{(\w+)\}/g, (_, k) => (ctx[k] ?? ''));
|
|
556
|
-
// :key (avoid matching protocol like http://)
|
|
557
|
-
out = out.replace(/(^|[^:]):(\w+)/g, (m, prefix, k) => `${prefix}${ctx[k] ?? ''}`);
|
|
558
|
-
return out;
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
// String shorthand => treat as a template
|
|
562
|
-
if (typeof linkParams === 'string') {
|
|
563
|
-
const href = interpolate(linkParams, row);
|
|
564
|
-
return href; // no query in shorthand; use object form if you need query
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
// Safety
|
|
568
|
-
if (!linkParams || typeof linkParams !== 'object') return '';
|
|
569
|
-
|
|
570
|
-
// Template mode
|
|
571
|
-
if (linkParams.template) {
|
|
572
|
-
// Merge row first, then allow explicit overrides via params
|
|
573
|
-
const ctx = { ...(row || {}), ...(linkParams.params || {}) };
|
|
574
|
-
const href = interpolate(linkParams.template, ctx);
|
|
575
|
-
return appendQuery(href, linkParams.query);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// Route name mode (default/back-compat)
|
|
579
|
-
if (linkParams.name) {
|
|
580
|
-
const ids = Array.isArray(linkParams.resourceIds)
|
|
581
|
-
? linkParams.resourceIds.map((key) => (row ? row[key] : undefined))
|
|
582
|
-
: [];
|
|
583
|
-
|
|
584
|
-
// `route` comes from Ziggy; assume it is globally available as in your existing codebase
|
|
585
|
-
let href = route(linkParams.name, ids);
|
|
586
|
-
return appendQuery(href, linkParams.query);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// Nothing to build
|
|
590
|
-
return '';
|
|
591
|
-
},
|
|
592
634
|
selectAllRows() {
|
|
593
635
|
if (this.selectedRows.length == this.rows.length) {
|
|
594
636
|
this.selectedRows = [];
|
|
@@ -625,15 +667,42 @@ export default {
|
|
|
625
667
|
});
|
|
626
668
|
}
|
|
627
669
|
});
|
|
628
|
-
|
|
670
|
+
|
|
671
|
+
this.columnSettings.start = 0;
|
|
629
672
|
this.loadData();
|
|
630
673
|
},
|
|
631
674
|
getSelectedRows() {
|
|
632
675
|
return this.selectedRows;
|
|
633
676
|
},
|
|
677
|
+
t(key, replacements = {}) {
|
|
678
|
+
const packageLocale =
|
|
679
|
+
defaultVocabulary[this.locale] ??
|
|
680
|
+
defaultVocabulary.en;
|
|
681
|
+
|
|
682
|
+
const customLocale =
|
|
683
|
+
this.vocabulary[this.locale] ??
|
|
684
|
+
this.vocabulary.en;
|
|
685
|
+
|
|
686
|
+
let translation =
|
|
687
|
+
customLocale?.[key] ??
|
|
688
|
+
packageLocale?.[key] ??
|
|
689
|
+
defaultVocabulary.en[key] ??
|
|
690
|
+
key;
|
|
691
|
+
|
|
692
|
+
Object.entries(replacements).forEach(([name, value]) => {
|
|
693
|
+
translation = translation.replaceAll(
|
|
694
|
+
`{${name}}`,
|
|
695
|
+
String(value)
|
|
696
|
+
);
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
return translation;
|
|
700
|
+
},
|
|
634
701
|
},
|
|
635
|
-
|
|
702
|
+
created() {
|
|
636
703
|
this.initColumnSettings();
|
|
704
|
+
},
|
|
705
|
+
mounted() {
|
|
637
706
|
if (this.loadDataOnInit) {
|
|
638
707
|
this.loadData();
|
|
639
708
|
}
|
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
|
+
};
|