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