@sulzanoks/vue-datatable 0.1.0 → 0.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 +4 -0
- package/dist/datatable-card.es.js +1074 -1039
- package/dist/datatable-card.umd.js +6 -6
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/Components/DatatableCard.vue +439 -412
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="card" :class="cardClasses">
|
|
3
|
-
<header class="card-header"
|
|
3
|
+
<header class="card-header"
|
|
4
|
+
:class="{ 'card-header-primary': !cardError && cardIcon, 'card-header-danger': cardError && cardIcon, 'card-header-icon': cardIcon }">
|
|
4
5
|
<div v-if="cardIcon" class="card-icon">
|
|
5
|
-
<i v-if="!cardError" class="material-icons">{{cardIcon}}</i>
|
|
6
|
+
<i v-if="!cardError" class="material-icons">{{ cardIcon }}</i>
|
|
6
7
|
<i v-else class="material-icons">dangerous</i>
|
|
7
8
|
</div>
|
|
8
|
-
<h4 v-if="cardTitle && !cardError" class="card-title">{{cardTitle}}</h4>
|
|
9
|
-
<h4 v-if="cardError" class="card-title text-danger">{{cardError}}</h4>
|
|
10
|
-
<div v-if="!advancedSearch" class="card-search" :class="{open:searchBarOpen}">
|
|
9
|
+
<h4 v-if="cardTitle && !cardError" class="card-title">{{ cardTitle }}</h4>
|
|
10
|
+
<h4 v-if="cardError" class="card-title text-danger">{{ cardError }}</h4>
|
|
11
|
+
<div v-if="!advancedSearch" class="card-search" :class="{ open: searchBarOpen }">
|
|
11
12
|
<div class="form-group label-floating is-empty">
|
|
12
13
|
<i class="material-icons search-icon-left">search</i>
|
|
13
|
-
<input type="text" class="form-control filter-input" placeholder="Search..." autocomplete="off"
|
|
14
|
+
<input type="text" class="form-control filter-input" placeholder="Search..." autocomplete="off"
|
|
15
|
+
@keyup="setSearchTerm">
|
|
14
16
|
<a href="javascript:void(0)" class="close-search" @click="clearSearch" data-tippy-content="Close">
|
|
15
17
|
<i class="material-icons">close</i>
|
|
16
18
|
</a>
|
|
@@ -19,8 +21,8 @@
|
|
|
19
21
|
<ul class="card-actions icons right-top">
|
|
20
22
|
<slot name="actions"></slot>
|
|
21
23
|
<li v-if="createLink">
|
|
22
|
-
<Link
|
|
23
|
-
|
|
24
|
+
<Link :href="createLink" data-tippy-content="Create new">
|
|
25
|
+
<i class="material-icons">add</i>
|
|
24
26
|
</Link>
|
|
25
27
|
</li>
|
|
26
28
|
<li>
|
|
@@ -50,21 +52,13 @@
|
|
|
50
52
|
</ul>
|
|
51
53
|
</header>
|
|
52
54
|
<div class="card-body">
|
|
53
|
-
<slot></slot>
|
|
54
|
-
<div v-if="advancedSearch" class="toolbar" :class="{open:searchBarOpen}">
|
|
55
|
+
<slot name="default"></slot>
|
|
56
|
+
<div v-if="advancedSearch" class="toolbar" :class="{ open: searchBarOpen }">
|
|
55
57
|
<form @submit.prevent="setAdvancedSearchFilters">
|
|
56
|
-
<template
|
|
57
|
-
<span
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
:key="index"
|
|
61
|
-
>
|
|
62
|
-
<input
|
|
63
|
-
:name="column.name"
|
|
64
|
-
class="form-control advanced-filter-input"
|
|
65
|
-
:placeholder="column.displayName"
|
|
66
|
-
autocomplete="off"
|
|
67
|
-
/>
|
|
58
|
+
<template v-for="(column, index) in columns">
|
|
59
|
+
<span v-if="column.searchable !== false" class="bmd-form-group" :key="index">
|
|
60
|
+
<input :name="column.name" class="form-control advanced-filter-input"
|
|
61
|
+
:placeholder="column.displayName" autocomplete="off" />
|
|
68
62
|
</span>
|
|
69
63
|
</template>
|
|
70
64
|
<button type="submit" class="btn btn-primary">Meklēt</button>
|
|
@@ -72,78 +66,72 @@
|
|
|
72
66
|
</div>
|
|
73
67
|
<div class="table-responsive">
|
|
74
68
|
<div class="dataTables_wrapper no-footer">
|
|
75
|
-
<table class="table data-table dataTable no-footer">
|
|
69
|
+
<table class="table data-table dataTable no-footer" :class="{'table-hover' : clickableRows}">
|
|
76
70
|
<thead>
|
|
77
71
|
<tr>
|
|
78
72
|
<th v-if="selectableRows">
|
|
79
73
|
<input type="checkbox" @click="selectAllRows" ref="selectAllRows">
|
|
80
74
|
</th>
|
|
81
|
-
<template
|
|
82
|
-
v-
|
|
83
|
-
:key="index"
|
|
84
|
-
>
|
|
85
|
-
<th
|
|
86
|
-
v-if="column.visible !== false"
|
|
75
|
+
<template v-for="(column, index) in columns" :key="index">
|
|
76
|
+
<th v-if="column.visible !== false"
|
|
87
77
|
:class="[columnSortingClasses[index], column.sortable !== false ? 'sorting' : '']"
|
|
88
|
-
@click="setSorting(index)"
|
|
89
|
-
|
|
90
|
-
{{column.displayName}}
|
|
78
|
+
@click="setSorting(index)">
|
|
79
|
+
{{ column.displayName }}
|
|
91
80
|
</th>
|
|
92
81
|
</template>
|
|
82
|
+
<th v-if="actions" class="w-25">Darbības</th>
|
|
93
83
|
</tr>
|
|
94
84
|
</thead>
|
|
95
85
|
<tbody>
|
|
96
|
-
<tr
|
|
86
|
+
<tr
|
|
87
|
+
v-for="(row, index) in rows"
|
|
88
|
+
:key="index"
|
|
89
|
+
@click="clickableRows ? $emit('row-click', row) : null"
|
|
90
|
+
>
|
|
97
91
|
<td v-if="selectableRows">
|
|
98
92
|
<input type="checkbox" :value="row.id" v-model="selectedRows">
|
|
99
93
|
</td>
|
|
100
94
|
<template v-for="(column, index) in columns" :key="index">
|
|
101
95
|
<td v-if="column.visible !== false">
|
|
102
|
-
<Link v-if="column.linkParams" :href="generateLink(column.linkParams, row)"
|
|
96
|
+
<Link v-if="column.linkParams" :href="generateLink(column.linkParams, row)"
|
|
97
|
+
v-html="row[column.data]">
|
|
103
98
|
</Link>
|
|
104
99
|
<span v-else v-html="row[column.data]"></span>
|
|
105
100
|
</td>
|
|
106
101
|
</template>
|
|
102
|
+
<td v-if="actions">
|
|
103
|
+
<button v-for="(action, index) in actions" :key="index" class="btn btn-sm"
|
|
104
|
+
:class="action.class" @click="handleEmit(action.emit, row)">
|
|
105
|
+
<i v-if="action.icon" class="material-icons">{{ action.icon }}</i> {{
|
|
106
|
+
action.label
|
|
107
|
+
}}
|
|
108
|
+
</button>
|
|
109
|
+
</td>
|
|
107
110
|
</tr>
|
|
108
111
|
</tbody>
|
|
109
112
|
</table>
|
|
110
113
|
|
|
111
114
|
<div class="dataTables_info">
|
|
112
|
-
Rāda {{firstRecord}}. līdz {{lastRecord}}. no {{recordsFiltered}} ierakstiem
|
|
115
|
+
Rāda {{ firstRecord }}. līdz {{ lastRecord }}. no {{ recordsFiltered }} ierakstiem
|
|
113
116
|
<span v-if="recordsFiltered != recordsTotal">
|
|
114
117
|
(kopā {{ recordsTotal }} ierkasti)
|
|
115
118
|
</span>
|
|
116
119
|
</div>
|
|
117
|
-
<div class="dataTables_paginate paging_simple_numbers user-select-none"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
<a
|
|
124
|
-
class="paginate_button previous"
|
|
125
|
-
:class="{disabled:columnSettings.start == 0}"
|
|
126
|
-
@click="setPage(currentPage - 1)"
|
|
127
|
-
>Iepriekšējā</a>
|
|
120
|
+
<div class="dataTables_paginate paging_simple_numbers user-select-none"
|
|
121
|
+
id="document-index-table_paginate">
|
|
122
|
+
<a class="paginate_button first user-select-none" :class="{ disabled: columnSettings.start == 0 }"
|
|
123
|
+
@click="setPage(1)">Pirmā</a>
|
|
124
|
+
<a class="paginate_button previous" :class="{ disabled: columnSettings.start == 0 }"
|
|
125
|
+
@click="setPage(currentPage - 1)">Iepriekšējā</a>
|
|
128
126
|
|
|
129
127
|
<span>
|
|
130
|
-
<a
|
|
131
|
-
|
|
132
|
-
class="paginate_button"
|
|
133
|
-
:class="{current: page == currentPage}"
|
|
134
|
-
@click="setPage(page)"
|
|
135
|
-
>{{ page }}</a>
|
|
128
|
+
<a v-for="(page, index) in pages" class="paginate_button"
|
|
129
|
+
:class="{ current: page == currentPage }" @click="setPage(page)">{{ page }}</a>
|
|
136
130
|
</span>
|
|
137
|
-
<a
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
@click="setPage(
|
|
141
|
-
>Nākamā</a>
|
|
142
|
-
<a
|
|
143
|
-
class="paginate_button last"
|
|
144
|
-
:class="{disabled:columnSettings.start >= lastPageStart}"
|
|
145
|
-
@click="setPage(pageCount)"
|
|
146
|
-
>Pēdējā</a>
|
|
131
|
+
<a class="paginate_button next" :class="{ disabled: columnSettings.start >= lastPageStart }"
|
|
132
|
+
@click="setPage(currentPage + 1)">Nākamā</a>
|
|
133
|
+
<a class="paginate_button last" :class="{ disabled: columnSettings.start >= lastPageStart }"
|
|
134
|
+
@click="setPage(pageCount)">Pēdējā</a>
|
|
147
135
|
</div>
|
|
148
136
|
|
|
149
137
|
</div>
|
|
@@ -153,371 +141,383 @@
|
|
|
153
141
|
</template>
|
|
154
142
|
|
|
155
143
|
<script>
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
dir: 'asc',
|
|
211
|
-
}
|
|
212
|
-
],
|
|
213
|
-
},
|
|
214
|
-
advancedSearch: {
|
|
215
|
-
type: Boolean,
|
|
216
|
-
required: false,
|
|
217
|
-
default: false,
|
|
218
|
-
},
|
|
219
|
-
loadDataOnInit: {
|
|
220
|
-
type: Boolean,
|
|
221
|
-
required: false,
|
|
222
|
-
default: true,
|
|
223
|
-
},
|
|
224
|
-
requestQueryParams: {
|
|
225
|
-
type: Object,
|
|
226
|
-
required: false,
|
|
227
|
-
default: () => {
|
|
228
|
-
return {};
|
|
144
|
+
import axios from 'axios';
|
|
145
|
+
import { Link } from '@inertiajs/vue3';
|
|
146
|
+
|
|
147
|
+
export default {
|
|
148
|
+
name: "DatatableCard",
|
|
149
|
+
components: {
|
|
150
|
+
Link,
|
|
151
|
+
},
|
|
152
|
+
props: {
|
|
153
|
+
cardTitle: {
|
|
154
|
+
type: String,
|
|
155
|
+
required: false,
|
|
156
|
+
default: null,
|
|
157
|
+
},
|
|
158
|
+
cardIconStyle: {
|
|
159
|
+
type: String,
|
|
160
|
+
required: false,
|
|
161
|
+
default: 'card-header-primary',
|
|
162
|
+
},
|
|
163
|
+
cardIcon: {
|
|
164
|
+
type: String,
|
|
165
|
+
required: false,
|
|
166
|
+
default: null,
|
|
167
|
+
},
|
|
168
|
+
cardClasses: {
|
|
169
|
+
type: String,
|
|
170
|
+
required: false,
|
|
171
|
+
default: null,
|
|
172
|
+
},
|
|
173
|
+
createLink: {
|
|
174
|
+
type: String,
|
|
175
|
+
required: false,
|
|
176
|
+
default: null,
|
|
177
|
+
},
|
|
178
|
+
columns: {
|
|
179
|
+
type: Array,
|
|
180
|
+
required: true,
|
|
181
|
+
},
|
|
182
|
+
url: {
|
|
183
|
+
type: String,
|
|
184
|
+
required: true,
|
|
185
|
+
},
|
|
186
|
+
selectableRows: {
|
|
187
|
+
type: Boolean,
|
|
188
|
+
required: false,
|
|
189
|
+
default: false,
|
|
190
|
+
},
|
|
191
|
+
order: {
|
|
192
|
+
type: Array,
|
|
193
|
+
required: false,
|
|
194
|
+
default: [
|
|
195
|
+
{
|
|
196
|
+
column: 0,
|
|
197
|
+
dir: 'asc',
|
|
229
198
|
}
|
|
230
|
-
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
advancedSearch: {
|
|
202
|
+
type: Boolean,
|
|
203
|
+
required: false,
|
|
204
|
+
default: false,
|
|
205
|
+
},
|
|
206
|
+
loadDataOnInit: {
|
|
207
|
+
type: Boolean,
|
|
208
|
+
required: false,
|
|
209
|
+
default: true,
|
|
210
|
+
},
|
|
211
|
+
requestQueryParams: {
|
|
212
|
+
type: Object,
|
|
213
|
+
required: false,
|
|
214
|
+
default: () => {
|
|
215
|
+
return {};
|
|
242
216
|
}
|
|
243
217
|
},
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
218
|
+
actions: {
|
|
219
|
+
type: Array,
|
|
220
|
+
required: false,
|
|
221
|
+
},
|
|
222
|
+
clickableRows: {
|
|
223
|
+
type: Boolean,
|
|
224
|
+
required: false,
|
|
225
|
+
default: false,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
emits: ['row-click'],
|
|
229
|
+
data() {
|
|
230
|
+
return {
|
|
231
|
+
searchBarOpen: false,
|
|
232
|
+
rows: [],
|
|
233
|
+
columnSettings: {},
|
|
234
|
+
searchTerm: '',
|
|
235
|
+
recordsTotal: 0,
|
|
236
|
+
recordsFiltered: 0,
|
|
237
|
+
selectedRows: [],
|
|
238
|
+
cardError: null,
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
watch: {
|
|
242
|
+
selectedRows: function (val, oldVal) {
|
|
243
|
+
if (!this.selectableRows) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
249
246
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
247
|
+
if (val.length === this.rows.length && val.length > 0) {
|
|
248
|
+
this.$refs.selectAllRows.indeterminate = false;
|
|
249
|
+
this.$refs.selectAllRows.checked = true;
|
|
250
|
+
} else if (val.length === 0) {
|
|
251
|
+
this.$refs.selectAllRows.indeterminate = false;
|
|
252
|
+
this.$refs.selectAllRows.checked = false;
|
|
253
|
+
} else {
|
|
254
|
+
this.$refs.selectAllRows.indeterminate = true;
|
|
259
255
|
}
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
computed: {
|
|
259
|
+
firstRecord() {
|
|
260
|
+
return this.columnSettings.start + 1;
|
|
260
261
|
},
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
pageCount
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
let classes = [];
|
|
279
|
-
if(!this.columnSettings.order){
|
|
280
|
-
return classes;
|
|
281
|
-
}
|
|
262
|
+
lastRecord() {
|
|
263
|
+
return this.columnSettings.start + this.rows.length;
|
|
264
|
+
},
|
|
265
|
+
currentPage() {
|
|
266
|
+
return Math.ceil(this.columnSettings.start / this.columnSettings.length) + 1;
|
|
267
|
+
},
|
|
268
|
+
pageCount() {
|
|
269
|
+
return Math.ceil(this.recordsFiltered / this.columnSettings.length);
|
|
270
|
+
},
|
|
271
|
+
lastPageStart() {
|
|
272
|
+
return (this.pageCount - 1) * this.columnSettings.length;
|
|
273
|
+
},
|
|
274
|
+
columnSortingClasses() {
|
|
275
|
+
let classes = [];
|
|
276
|
+
if (!this.columnSettings.order) {
|
|
277
|
+
return classes;
|
|
278
|
+
}
|
|
282
279
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
280
|
+
for (let i = 0; i < this.columns.length; i++) {
|
|
281
|
+
let sortDirection = '';
|
|
282
|
+
for (let j = 0; j < this.columnSettings.order.length; j++) {
|
|
283
|
+
if (this.columnSettings.order[j].column == i) {
|
|
284
|
+
sortDirection = this.columnSettings.order[j].dir == 'asc' ? 'sorting_asc' : 'sorting_desc';
|
|
289
285
|
}
|
|
290
|
-
classes.push(sortDirection);
|
|
291
|
-
}
|
|
292
|
-
return classes;
|
|
293
|
-
},
|
|
294
|
-
pages(){
|
|
295
|
-
let pages = [];
|
|
296
|
-
let start = this.currentPage - 2;
|
|
297
|
-
let end = this.currentPage + 2;
|
|
298
|
-
if(start < 1){
|
|
299
|
-
start = 1;
|
|
300
|
-
end = 5;
|
|
301
|
-
}
|
|
302
|
-
if(end > this.pageCount){
|
|
303
|
-
start = this.pageCount - 4;
|
|
304
|
-
end = this.pageCount;
|
|
305
|
-
}
|
|
306
|
-
if(start < 1){
|
|
307
|
-
start = 1;
|
|
308
|
-
}
|
|
309
|
-
for(let i = start; i <= end; i++){
|
|
310
|
-
pages.push(i);
|
|
311
|
-
}
|
|
312
|
-
return pages;
|
|
313
|
-
},
|
|
314
|
-
},
|
|
315
|
-
methods:{
|
|
316
|
-
refresh(){
|
|
317
|
-
this.initColumnSettings();
|
|
318
|
-
this.searchBarOpen = false;
|
|
319
|
-
if (this.loadDataOnInit) {
|
|
320
|
-
this.loadData();
|
|
321
|
-
} else {
|
|
322
|
-
this.rows = [];
|
|
323
286
|
}
|
|
287
|
+
classes.push(sortDirection);
|
|
288
|
+
}
|
|
289
|
+
return classes;
|
|
290
|
+
},
|
|
291
|
+
pages() {
|
|
292
|
+
let pages = [];
|
|
293
|
+
let start = this.currentPage - 2;
|
|
294
|
+
let end = this.currentPage + 2;
|
|
295
|
+
if (start < 1) {
|
|
296
|
+
start = 1;
|
|
297
|
+
end = 5;
|
|
298
|
+
}
|
|
299
|
+
if (end > this.pageCount) {
|
|
300
|
+
start = this.pageCount - 4;
|
|
301
|
+
end = this.pageCount;
|
|
302
|
+
}
|
|
303
|
+
if (start < 1) {
|
|
304
|
+
start = 1;
|
|
305
|
+
}
|
|
306
|
+
for (let i = start; i <= end; i++) {
|
|
307
|
+
pages.push(i);
|
|
308
|
+
}
|
|
309
|
+
return pages;
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
methods: {
|
|
313
|
+
handleEmit(emit, row) {
|
|
314
|
+
this.$emit(emit, row);
|
|
315
|
+
},
|
|
316
|
+
refresh() {
|
|
317
|
+
this.initColumnSettings();
|
|
318
|
+
this.searchBarOpen = false;
|
|
319
|
+
if (this.loadDataOnInit) {
|
|
320
|
+
this.loadData();
|
|
321
|
+
} else {
|
|
322
|
+
this.rows = [];
|
|
323
|
+
}
|
|
324
324
|
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
// clear selected rows
|
|
326
|
+
this.selectedRows = [];
|
|
327
327
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
328
|
+
// clear search bar
|
|
329
|
+
if (!this.advancedSearch) {
|
|
330
|
+
this.$el.querySelector('.filter-input').value = '';
|
|
331
|
+
}
|
|
332
|
+
// clear advanced search inputs
|
|
333
|
+
this.$el.querySelectorAll('.advanced-filter-input').forEach((input) => {
|
|
334
|
+
input.value = '';
|
|
335
|
+
});
|
|
336
|
+
},
|
|
337
337
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
338
|
+
toggleSearch() {
|
|
339
|
+
if (!this.advancedSearch) {
|
|
340
|
+
this.searchBarOpen = true;
|
|
341
|
+
}
|
|
342
342
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
343
|
+
if (this.advancedSearch) {
|
|
344
|
+
this.searchBarOpen = !this.searchBarOpen;
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
clearSearch() {
|
|
348
|
+
this.searchBarOpen = false;
|
|
349
|
+
this.$el.querySelector('.filter-input').value = '';
|
|
350
|
+
this.columnSettings.search.value = '';
|
|
351
351
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
352
|
+
this.loadData();
|
|
353
|
+
},
|
|
354
|
+
setAdvancedSearchFilters() {
|
|
355
|
+
this.columnSettings.columns.forEach((column, index) => {
|
|
356
|
+
if (column.searchable) {
|
|
357
|
+
column.search.value = this.$el.querySelector(`input[name="${column.name}"]`).value;
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
this.loadData();
|
|
361
|
+
},
|
|
362
|
+
loadData() {
|
|
363
|
+
this.columnSettings.draw++;
|
|
364
|
+
this.clearSelectedRows();
|
|
365
|
+
const params = {
|
|
366
|
+
...this.requestQueryParams,
|
|
367
|
+
...this.columnSettings,
|
|
368
|
+
};
|
|
369
|
+
axios.get(this.url, { params: params }).then(response => {
|
|
370
|
+
if (response.data.error) {
|
|
371
|
+
this.cardError = 'error loading data. see console for details';
|
|
372
|
+
console.error(response.data.error);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
375
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
376
|
+
this.cardError = null;
|
|
377
|
+
this.rows = response.data.data;
|
|
378
|
+
this.recordsTotal = response.data.recordsTotal;
|
|
379
|
+
this.recordsFiltered = response.data.recordsFiltered;
|
|
380
|
+
})
|
|
381
381
|
.catch(error => {
|
|
382
382
|
this.cardError = error.response.data.message;
|
|
383
383
|
console.error(error);
|
|
384
384
|
});
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}),
|
|
403
|
-
order: this.order,
|
|
404
|
-
start: 0,
|
|
405
|
-
length: 10,
|
|
406
|
-
search: {
|
|
407
|
-
value: '',
|
|
408
|
-
regex: false,
|
|
409
|
-
},
|
|
410
|
-
}
|
|
411
|
-
},
|
|
412
|
-
setPageLength(length){
|
|
413
|
-
this.columnSettings.length = length;
|
|
414
|
-
this.loadData();
|
|
415
|
-
},
|
|
416
|
-
setPage(page){
|
|
417
|
-
if(page < 1 || page > this.pageCount){
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
this.columnSettings.start = (page - 1) * this.columnSettings.length;
|
|
421
|
-
this.loadData();
|
|
422
|
-
},
|
|
423
|
-
setSearchTerm(){
|
|
424
|
-
// wait for user to stop typing
|
|
425
|
-
setTimeout(() => {
|
|
426
|
-
this.columnSettings.search.value = this.$el.querySelector('.filter-input').value;
|
|
427
|
-
this.columnSettings.start = 0;
|
|
428
|
-
// set search term for each column if searchable
|
|
429
|
-
// this.columnSettings.columns.forEach((column, index) => {
|
|
430
|
-
// if(column.searchable){
|
|
431
|
-
// column.search.value = this.columnSettings.search.value;
|
|
432
|
-
// }
|
|
433
|
-
// });
|
|
434
|
-
this.loadData();
|
|
435
|
-
}, 500);
|
|
436
|
-
},
|
|
437
|
-
setSorting(index){
|
|
438
|
-
// if column is not sortable, do nothing
|
|
439
|
-
if(!this.columnSettings.columns[index].sortable){
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
// console.log('sorting');
|
|
443
|
-
// // if column is already sorted, reverse sort direction
|
|
444
|
-
if(this.columnSettings.order[0].column == index){
|
|
445
|
-
this.columnSettings.order[0].dir = this.columnSettings.order[0].dir == 'asc' ? 'desc' : 'asc';
|
|
446
|
-
}else{
|
|
447
|
-
// if column is not sorted, set it as first sort column
|
|
448
|
-
this.columnSettings.order = [
|
|
449
|
-
{
|
|
450
|
-
column: index,
|
|
451
|
-
dir: 'asc',
|
|
385
|
+
},
|
|
386
|
+
initColumnSettings() {
|
|
387
|
+
this.columnSettings = {
|
|
388
|
+
draw: 0,
|
|
389
|
+
columns: this.columns.map((column, index) => {
|
|
390
|
+
return {
|
|
391
|
+
data: column.data,
|
|
392
|
+
name: column.name,
|
|
393
|
+
// if searchable is not set, default to true
|
|
394
|
+
searchable: column.searchable === undefined ? true : column.searchable,
|
|
395
|
+
sortable: column.sortable === undefined ? true : column.sortable,
|
|
396
|
+
visible: column.visible === undefined ? true : column.visible,
|
|
397
|
+
search: {
|
|
398
|
+
value: '',
|
|
399
|
+
regex: false,
|
|
452
400
|
}
|
|
453
|
-
|
|
454
|
-
}
|
|
401
|
+
}
|
|
402
|
+
}),
|
|
403
|
+
order: this.order,
|
|
404
|
+
start: 0,
|
|
405
|
+
length: 10,
|
|
406
|
+
search: {
|
|
407
|
+
value: '',
|
|
408
|
+
regex: false,
|
|
409
|
+
},
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
setPageLength(length) {
|
|
413
|
+
this.columnSettings.length = length;
|
|
414
|
+
this.loadData();
|
|
415
|
+
},
|
|
416
|
+
setPage(page) {
|
|
417
|
+
if (page < 1 || page > this.pageCount) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
this.columnSettings.start = (page - 1) * this.columnSettings.length;
|
|
421
|
+
this.loadData();
|
|
422
|
+
},
|
|
423
|
+
setSearchTerm() {
|
|
424
|
+
// wait for user to stop typing
|
|
425
|
+
setTimeout(() => {
|
|
426
|
+
this.columnSettings.search.value = this.$el.querySelector('.filter-input').value;
|
|
427
|
+
this.columnSettings.start = 0;
|
|
428
|
+
// set search term for each column if searchable
|
|
429
|
+
// this.columnSettings.columns.forEach((column, index) => {
|
|
430
|
+
// if(column.searchable){
|
|
431
|
+
// column.search.value = this.columnSettings.search.value;
|
|
432
|
+
// }
|
|
433
|
+
// });
|
|
455
434
|
this.loadData();
|
|
456
|
-
},
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
435
|
+
}, 500);
|
|
436
|
+
},
|
|
437
|
+
setSorting(index) {
|
|
438
|
+
// if column is not sortable, do nothing
|
|
439
|
+
if (!this.columnSettings.columns[index].sortable) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
// console.log('sorting');
|
|
443
|
+
// // if column is already sorted, reverse sort direction
|
|
444
|
+
if (this.columnSettings.order[0].column == index) {
|
|
445
|
+
this.columnSettings.order[0].dir = this.columnSettings.order[0].dir == 'asc' ? 'desc' : 'asc';
|
|
446
|
+
} else {
|
|
447
|
+
// if column is not sorted, set it as first sort column
|
|
448
|
+
this.columnSettings.order = [
|
|
449
|
+
{
|
|
450
|
+
column: index,
|
|
451
|
+
dir: 'asc',
|
|
452
|
+
}
|
|
453
|
+
];
|
|
454
|
+
}
|
|
455
|
+
this.loadData();
|
|
456
|
+
},
|
|
457
|
+
generateLink(linkParams, row) {
|
|
458
|
+
let resourceIds = [];
|
|
459
|
+
linkParams.resourceIds.forEach((resourceId) => {
|
|
460
|
+
resourceIds.push(row[resourceId]);
|
|
461
|
+
});
|
|
462
462
|
|
|
463
|
-
|
|
463
|
+
let link = route(linkParams.name, resourceIds);
|
|
464
464
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
this.selectedRows = [];
|
|
473
|
-
}else{
|
|
474
|
-
this.selectedRows = this.rows.map((row) => {
|
|
475
|
-
return row.id;
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
},
|
|
479
|
-
clearSelectedRows(){
|
|
465
|
+
if (linkParams.query) {
|
|
466
|
+
link += '?' + new URLSearchParams(linkParams.query).toString();
|
|
467
|
+
}
|
|
468
|
+
return link;
|
|
469
|
+
},
|
|
470
|
+
selectAllRows() {
|
|
471
|
+
if (this.selectedRows.length == this.rows.length) {
|
|
480
472
|
this.selectedRows = [];
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
// [
|
|
485
|
-
// {
|
|
486
|
-
// name: 'name',
|
|
487
|
-
// value: 'John',
|
|
488
|
-
// },
|
|
489
|
-
// {
|
|
490
|
-
// name: 'email',
|
|
491
|
-
// value: 'john@example',
|
|
492
|
-
// },
|
|
493
|
-
// ]
|
|
494
|
-
|
|
495
|
-
// set search term for each column if searchable
|
|
496
|
-
this.columnSettings.columns.forEach((column, index) => {
|
|
497
|
-
if(column.searchable){
|
|
498
|
-
column.search.value = '';
|
|
499
|
-
params.forEach((param) => {
|
|
500
|
-
if(param.name == column.name){
|
|
501
|
-
column.search.value = param.value;
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
}
|
|
473
|
+
} else {
|
|
474
|
+
this.selectedRows = this.rows.map((row) => {
|
|
475
|
+
return row.id;
|
|
505
476
|
});
|
|
477
|
+
}
|
|
478
|
+
},
|
|
479
|
+
clearSelectedRows() {
|
|
480
|
+
this.selectedRows = [];
|
|
481
|
+
},
|
|
482
|
+
filterColumns(params) {
|
|
483
|
+
// param example
|
|
484
|
+
// [
|
|
485
|
+
// {
|
|
486
|
+
// name: 'name',
|
|
487
|
+
// value: 'John',
|
|
488
|
+
// },
|
|
489
|
+
// {
|
|
490
|
+
// name: 'email',
|
|
491
|
+
// value: 'john@example',
|
|
492
|
+
// },
|
|
493
|
+
// ]
|
|
494
|
+
|
|
495
|
+
// set search term for each column if searchable
|
|
496
|
+
this.columnSettings.columns.forEach((column, index) => {
|
|
497
|
+
if (column.searchable) {
|
|
498
|
+
column.search.value = '';
|
|
499
|
+
params.forEach((param) => {
|
|
500
|
+
if (param.name == column.name) {
|
|
501
|
+
column.search.value = param.value;
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
506
|
|
|
507
|
-
|
|
508
|
-
},
|
|
509
|
-
getSelectedRows(){
|
|
510
|
-
return this.selectedRows;
|
|
511
|
-
},
|
|
507
|
+
this.loadData();
|
|
512
508
|
},
|
|
513
|
-
|
|
514
|
-
this.
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
509
|
+
getSelectedRows() {
|
|
510
|
+
return this.selectedRows;
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
mounted() {
|
|
514
|
+
this.initColumnSettings();
|
|
515
|
+
if (this.loadDataOnInit) {
|
|
516
|
+
this.loadData();
|
|
518
517
|
}
|
|
519
|
-
|
|
520
518
|
}
|
|
519
|
+
|
|
520
|
+
}
|
|
521
521
|
</script>
|
|
522
522
|
|
|
523
523
|
<style scoped>
|
|
@@ -559,7 +559,9 @@
|
|
|
559
559
|
left: 15px;
|
|
560
560
|
right: auto;
|
|
561
561
|
}
|
|
562
|
-
|
|
562
|
+
|
|
563
|
+
.card .card-search .close-search,
|
|
564
|
+
.card .card-search .search-icon-left {
|
|
563
565
|
top: 50%;
|
|
564
566
|
margin-top: -15px;
|
|
565
567
|
line-height: 30px;
|
|
@@ -589,7 +591,8 @@
|
|
|
589
591
|
right: 15px;
|
|
590
592
|
left: auto;
|
|
591
593
|
}
|
|
592
|
-
|
|
594
|
+
|
|
595
|
+
.card .card-search .search-icon-left {
|
|
593
596
|
top: 50%;
|
|
594
597
|
margin-top: -15px;
|
|
595
598
|
line-height: 30px;
|
|
@@ -642,7 +645,7 @@ ul.card-actions.icons li {
|
|
|
642
645
|
min-width: 30px;
|
|
643
646
|
height: 30px;
|
|
644
647
|
line-height: 30px;
|
|
645
|
-
color: #999999!important;
|
|
648
|
+
color: #999999 !important;
|
|
646
649
|
font-weight: 400;
|
|
647
650
|
font-size: 12px;
|
|
648
651
|
text-transform: uppercase;
|
|
@@ -663,7 +666,8 @@ ul.card-actions.icons li {
|
|
|
663
666
|
background: transparent;
|
|
664
667
|
}
|
|
665
668
|
|
|
666
|
-
.card [class*=card-header-],
|
|
669
|
+
.card [class*=card-header-],
|
|
670
|
+
.card[class*=bg-] {
|
|
667
671
|
color: #ffffff;
|
|
668
672
|
}
|
|
669
673
|
|
|
@@ -677,15 +681,23 @@ ul.card-actions.icons li {
|
|
|
677
681
|
position: relative;
|
|
678
682
|
}
|
|
679
683
|
|
|
680
|
-
.card .card-header-primary .card-icon,
|
|
684
|
+
.card .card-header-primary .card-icon,
|
|
685
|
+
.card .card-header-primary .card-text,
|
|
686
|
+
.card .card-header-primary:not(.card-header-icon):not(.card-header-text),
|
|
687
|
+
.card.bg-primary,
|
|
688
|
+
.card.card-rotate.bg-primary .front,
|
|
689
|
+
.card.card-rotate.bg-primary .back {
|
|
681
690
|
background: linear-gradient(60deg, #ab47bc, #8e24aa);
|
|
682
691
|
}
|
|
683
692
|
|
|
684
|
-
.card .card-header-primary .card-icon,
|
|
693
|
+
.card .card-header-primary .card-icon,
|
|
694
|
+
.card .card-header-primary:not(.card-header-icon):not(.card-header-text),
|
|
695
|
+
.card .card-header-primary .card-text {
|
|
685
696
|
box-shadow: 0 4px 20px 0px rgba(0, 0, 0, 0.14), 0 7px 10px -5px rgba(156, 39, 176, 0.4);
|
|
686
697
|
}
|
|
687
698
|
|
|
688
|
-
.card [class*=card-header-] .card-icon,
|
|
699
|
+
.card [class*=card-header-] .card-icon,
|
|
700
|
+
.card [class*=card-header-] .card-text {
|
|
689
701
|
border-radius: 3px;
|
|
690
702
|
background-color: #999999;
|
|
691
703
|
padding: 15px;
|
|
@@ -694,7 +706,8 @@ ul.card-actions.icons li {
|
|
|
694
706
|
float: left;
|
|
695
707
|
}
|
|
696
708
|
|
|
697
|
-
.card .card-header.card-header-icon i,
|
|
709
|
+
.card .card-header.card-header-icon i,
|
|
710
|
+
.card .card-header.card-header-text i {
|
|
698
711
|
width: 33px;
|
|
699
712
|
height: 33px;
|
|
700
713
|
text-align: center;
|
|
@@ -714,13 +727,17 @@ ul.card-actions.icons li {
|
|
|
714
727
|
font-size: 0.875rem;
|
|
715
728
|
}
|
|
716
729
|
|
|
717
|
-
.card .card-header.card-header-icon .card-title,
|
|
730
|
+
.card .card-header.card-header-icon .card-title,
|
|
731
|
+
.card .card-header.card-header-text .card-title {
|
|
718
732
|
margin-top: 15px;
|
|
719
733
|
color: #3C4858;
|
|
720
734
|
}
|
|
721
|
-
|
|
735
|
+
|
|
736
|
+
.card .card-header.card-header-icon h4,
|
|
737
|
+
.card .card-header.card-header-text h4 {
|
|
722
738
|
font-weight: 300;
|
|
723
739
|
}
|
|
740
|
+
|
|
724
741
|
.card .card-header .card-title {
|
|
725
742
|
margin-bottom: 3px;
|
|
726
743
|
}
|
|
@@ -765,7 +782,8 @@ ul.card-actions.icons li {
|
|
|
765
782
|
text-align: unset;
|
|
766
783
|
}
|
|
767
784
|
|
|
768
|
-
.dropdown-menu .dropdown-item,
|
|
785
|
+
.dropdown-menu .dropdown-item,
|
|
786
|
+
.dropdown-menu li>a {
|
|
769
787
|
position: relative;
|
|
770
788
|
width: auto;
|
|
771
789
|
display: flex;
|
|
@@ -786,13 +804,18 @@ ul.card-actions.icons li {
|
|
|
786
804
|
word-wrap: break-word;
|
|
787
805
|
}
|
|
788
806
|
|
|
789
|
-
.dropdown-menu .dropdown-item:hover,
|
|
807
|
+
.dropdown-menu .dropdown-item:hover,
|
|
808
|
+
.dropdown-menu .dropdown-item:focus,
|
|
809
|
+
.dropdown-menu a:hover,
|
|
810
|
+
.dropdown-menu a:focus,
|
|
811
|
+
.dropdown-menu a:active {
|
|
790
812
|
box-shadow: 0 4px 20px 0px rgba(0, 0, 0, 0.14), 0 7px 10px -5px rgba(156, 39, 176, 0.4);
|
|
791
813
|
background-color: #9c27b0;
|
|
792
814
|
color: #FFFFFF;
|
|
793
815
|
}
|
|
794
816
|
|
|
795
|
-
.dropdown-menu .dropdown-item,
|
|
817
|
+
.dropdown-menu .dropdown-item,
|
|
818
|
+
.dropdown-menu li>a {
|
|
796
819
|
padding-right: 1.5rem;
|
|
797
820
|
padding-left: 1.5rem;
|
|
798
821
|
}
|
|
@@ -831,4 +854,8 @@ ul.card-actions.icons li {
|
|
|
831
854
|
.dropdown-menu {
|
|
832
855
|
margin: 0 !important;
|
|
833
856
|
}
|
|
834
|
-
|
|
857
|
+
|
|
858
|
+
.clickable-rows tbody tr {
|
|
859
|
+
cursor: pointer;
|
|
860
|
+
}
|
|
861
|
+
</style>
|