1
1
<template >
2
2
<div >
3
3
<div v-if =" optionsRow" class =" row my-2 mx-0" >
4
- <div v-show =" optionsRow !== 'onlyPagination'" class =" col-sm-6 form-inline p-0" >
4
+
5
+ <div
6
+ v-show =" optionsRow !== 'onlyPagination'"
7
+ class =" col-sm-6 form-inline p-0"
8
+ >
5
9
<label class =" mr-2" >Filter: </label >
6
- <input class =" form-control c-table-filter"
7
- type =" text"
8
- placeholder =" type string..."
9
- @input =" tableFilter = $event.target.value"
10
- :value =" tableFilter"
10
+ <input
11
+ class =" form-control c-table-filter"
12
+ type =" text"
13
+ placeholder =" type string..."
14
+ @input =" tableFilter = $event.target.value"
15
+ :value =" tableFilter"
11
16
>
12
17
</div >
18
+
13
19
<div v-show =" optionsRow !== 'onlyFilter'" class =" col-sm-6 p-0" >
14
20
<div :class =" `form-inline ${optionsRow === 'onlyPagination' ? '' : 'float-sm-right'}`" >
15
21
<label class =" mr-2" >Items per page: </label >
16
- <input v-if =" false"
17
- class =" form-control"
18
- type =" number"
19
- placeholder =" type number..."
20
- @input =" perPageItems = Number($event.target.value)"
21
- >
22
- <select v-if =" true"
23
- class =" form-control"
24
- @change =" perPageItems = Number($event.target.value)"
22
+ <select
23
+ class =" form-control"
24
+ @change =" perPageItems = Number($event.target.value)"
25
25
>
26
- <option value =" " selected disabled hidden >{{perPageItems}}</option >
27
- <option v-for =" number in [5,10,20,50]" val =" number" >{{number}}</option >
26
+ <option value =" " selected disabled hidden >
27
+ {{perPageItems}}
28
+ </option >
29
+ <option v-for =" number in [5,10,20,50]" val =" number" >
30
+ {{number}}
31
+ </option >
28
32
</select >
29
33
</div >
30
34
</div >
31
35
</div >
36
+
37
+
32
38
<slot name =" overTable" />
33
- <div :class =" notResponsive ? '' : 'table-responsive'" class = " position-relative " >
39
+ <div :class =" `position-relative ${ notResponsive ? '' : 'table-responsive'}` " >
34
40
<table :class =" tableClasses" >
35
41
<thead :class =" headVariant ? `thead-${headVariant}` : ''" >
42
+
36
43
<tr >
37
- <th v-if =" indexCol " style =" width :40px " ></th >
44
+ <th v-if =" indexColumn " style =" width :40px " ></th >
38
45
<template v-for =" (name , index ) in columnNames " >
39
46
<th
40
47
@click =" changeSort(rawColumnNames[index], index)"
41
- :class =" [headerClass(index), iconStyles ]"
48
+ :class =" [headerClass(index), sortingIconStyles ]"
42
49
:style =" headerStyles(index)"
43
50
>
44
- <slot v-if =" $slots[`${rawColumnNames[index]}-header`]"
45
- :name =" `${rawColumnNames[index]}-header`"
46
- >
51
+ <slot :name =" `${rawColumnNames[index]}-header`" >
52
+ <div v-html =" name" class =" d-inline" ></div >
47
53
</slot >
48
- <div v-else v-html =" name" class =" d-inline" ></div >
49
54
<slot
50
55
v-if =" !noSorting && sortable(index)"
51
56
name =" sorting-icon"
56
61
</th >
57
62
</template >
58
63
</tr >
64
+
59
65
<tr v-if =" filterRow" class =" table-sm" >
60
- <th v-if =" indexCol" class =" pb-2" >
61
- <i v-if =" indexCol !== 'onlyIndexes'" class =" cui-ban icons text-danger font-lg text-center d-block" @click =" clear" title =" clear table" ></i >
66
+ <th v-if =" indexColumn" class =" pb-2" >
67
+ <i
68
+ v-if =" indexColumn !== 'onlyIndexes'"
69
+ class =" cui-ban icons text-danger font-lg text-center d-block"
70
+ @click =" clear"
71
+ title =" clear table"
72
+ ></i >
62
73
</th >
63
74
<template v-for =" (colName , index ) in rawColumnNames " >
64
75
<th :class =" headerClass(index)" >
65
- <slot :clear =" clear, colName, index"
66
- :name =" `${rawColumnNames[index]}-filter`"
76
+ <slot
77
+ :clear =" clear, colName, index"
78
+ :name =" `${rawColumnNames[index]}-filter`"
67
79
>
68
- <input v-if =" !fields || !fields[index].noFilter"
69
- class =" w-100 c-table-filter"
70
- @input =" addColumnFilter(colName, $event.target.value)"
71
- :value =" columnFilter[colName]"
80
+ <input
81
+ v-if =" !fields || !fields[index].noFilter"
82
+ class =" w-100 c-table-filter"
83
+ @input =" addColumnFilter(colName, $event.target.value)"
84
+ :value =" columnFilter[colName]"
72
85
></input >
73
86
</slot >
74
87
</th >
75
88
</template >
76
89
</tr >
77
90
</thead >
91
+
92
+
78
93
<tbody :style =" bodyStyle" class =" position-relative" >
79
94
<template v-for =" (item , itemIndex ) in currentItems " >
80
- <tr :class =" item._classes" :tabindex =" bodyStyle ? 0 : null"
81
- @click =" rowClicked(item, itemIndex + firstItemIndex)" >
82
- <slot v-if =" indexCol"
83
- name =" index-col"
84
- :index =" firstItemIndex + itemIndex"
95
+ <tr
96
+ :class =" item._classes" :tabindex =" bodyStyle ? 0 : null"
97
+ @click =" rowClicked(item, itemIndex + firstItemIndex)"
98
+ >
99
+ <slot
100
+ v-if =" indexColumn"
101
+ name =" index-col"
102
+ :index =" firstItemIndex + itemIndex"
85
103
>
86
104
<td >
87
- {{indexCol !== 'onlyCleaner' ? firstItemIndex + itemIndex + 1 : ''}}
105
+ {{indexColumn !== 'onlyCleaner' ? firstItemIndex + itemIndex + 1 : ''}}
88
106
</td >
89
107
</slot >
90
108
<template v-for =" (colName , index ) in rawColumnNames " >
91
- <slot v-if =" $scopedSlots[colName]"
92
- :name =" colName"
93
- :item =" item"
94
- :index =" itemIndex + firstItemIndex"
109
+ <slot
110
+ v-if =" $scopedSlots[colName]"
111
+ :name =" colName"
112
+ :item =" item"
113
+ :index =" itemIndex + firstItemIndex"
95
114
/>
96
- <td v-else
97
- :class =" cellClass(item, colName, index)"
98
- v-html =" item[colName]"
115
+ <td
116
+ v-else
117
+ :class =" cellClass(item, colName, index)"
118
+ v-html =" item[colName]"
99
119
></td >
100
120
</template >
101
121
</tr >
102
- <slot v-if =" $scopedSlots.details || $scopedSlots.detailsRow"
103
- name =" detailsRow"
104
- :item =" item"
105
- :index =" itemIndex + firstItemIndex"
106
- :colspan =" colspan" >
122
+ <slot
123
+ v-if =" $scopedSlots.details || $scopedSlots.detailsRow"
124
+ name =" detailsRow"
125
+ :item =" item"
126
+ :index =" itemIndex + firstItemIndex"
127
+ :colspan =" colspan"
128
+ >
107
129
<tr class =" p-0" style =" border :none !important " >
108
- <td :colspan =" colspan"
109
- class =" p-0"
110
- style =" border :none !important "
130
+ <td
131
+ :colspan =" colspan"
132
+ class =" p-0"
133
+ style =" border :none !important "
111
134
>
112
- <slot name =" details"
113
- :item =" item"
114
- :index =" itemIndex + firstItemIndex"
115
- :colspan =" colspan"
135
+ <slot
136
+ name =" details"
137
+ :item =" item"
138
+ :index =" itemIndex + firstItemIndex"
139
+ :colspan =" colspan"
116
140
/>
117
141
</td >
118
142
</tr >
123
147
<slot name =" empty-table" >
124
148
<div class =" text-center my-5" >
125
149
<h2 >{{ passedItems.length ? 'No filtering results ' : 'No items'}}
126
- <i style =" font-weight :1000 " class =" text-danger icons font-2xl cui-ban" ></i >
150
+ <i
151
+ style =" font-weight :1000 "
152
+ class =" text-danger icons
153
+ font-2xl cui-ban"
154
+ ></i >
127
155
</h2 >
128
156
</div >
129
157
</slot >
130
158
</td >
131
159
</tr >
132
160
</tbody >
161
+
162
+
133
163
<tfoot v-if =" footer && currentItems.length > 3" >
134
164
<tr >
135
- <th v-if =" indexCol " style =" width :40px " ></th >
165
+ <th v-if =" indexColumn " style =" width :40px " ></th >
136
166
<template v-for =" (name , index ) in columnNames " >
137
- <th @click =" changeSort(rawColumnNames[index], index)"
138
- :class =" [headerClass(index), iconStyles]"
139
- :style =" headerStyles(index)"
167
+ <th
168
+ @click =" changeSort(rawColumnNames[index], index)"
169
+ :class =" [headerClass(index), sortingIconStyles]"
170
+ :style =" headerStyles(index)"
140
171
>
141
- <slot v-if =" $slots[`${rawColumnNames[index]}-header`]"
142
- :name =" `${rawColumnNames[index]}-header`"
143
- >
172
+ <slot :name =" `${rawColumnNames[index]}-header`" >
173
+ <div v-html =" name" class =" d-inline" ></div >
144
174
</slot >
145
- <div v-else v-html =" name" class =" d-inline" ></div >
146
175
<slot
147
176
v-if =" !noSorting && sortable(index)"
148
177
name =" sorting-icon"
156
185
</tfoot >
157
186
<slot name =" caption" />
158
187
</table >
159
- <div v-if =" loading" :style =" topLoadingPosition" style =" position :absolute ;left :50% ;transform :translateX (-50% );" >
160
- <div class =" spinner-border text-success" :style =" spinnerSize" role =" status" >
188
+
189
+
190
+ <div
191
+ v-if =" loading"
192
+ :style =" topLoadingPosition"
193
+ style =" position :absolute ;left :50% ;transform :translateX (-50% );"
194
+ >
195
+ <div
196
+ class =" spinner-border text-success"
197
+ :style =" spinnerSize"
198
+ role =" status"
199
+ >
161
200
<span class =" sr-only" >Loading...</span >
162
201
</div >
163
202
</div >
164
203
</div >
165
204
<slot name =" underTable" />
205
+
206
+
166
207
<CPagination v-if =" !noPagination"
167
- v-show =" pages > 1"
208
+ v-show =" totalPages > 1"
168
209
v-model =" page"
169
- :pages =" pages "
210
+ :pages =" totalPages "
170
211
v-bind =" paginationProps"
171
212
/>
172
213
</div >
@@ -188,7 +229,7 @@ export default {
188
229
default: 10
189
230
},
190
231
activePage: Number ,
191
- indexCol : [Boolean , String ],
232
+ indexColumn : [Boolean , String ],
192
233
filterRow: Boolean ,
193
234
noPagination: Boolean ,
194
235
paginationProps: Object ,
@@ -224,7 +265,6 @@ export default {
224
265
sorter: { name: this .defaultSorter .name , direction: this .defaultSorter .direction },
225
266
firstItemIndex: 0 ,
226
267
page: this .activePage || 1 ,
227
- pages: 0 ,
228
268
perPageItems: this .perPage ,
229
269
passedItems: this .items
230
270
}
@@ -263,12 +303,14 @@ export default {
263
303
},
264
304
currentItems () {
265
305
if (this .computedPage ) {
266
- this .checkPagination ()
267
306
this .firstItemIndex = (this .computedPage - 1 ) * this .perPageItems
268
307
return this .sortedItems .slice (this .firstItemIndex , this .firstItemIndex + this .perPageItems )
269
308
}
270
309
return this .sortedItems
271
310
},
311
+ totalPages () {
312
+ return Math .ceil ((this .sortedItems .length )/ this .perPageItems ) || 1
313
+ },
272
314
computedPage () {
273
315
return this .noPagination ? this .activePage : this .page
274
316
},
@@ -307,8 +349,11 @@ export default {
307
349
bodyStyle () {
308
350
return this .$listeners && this .$listeners [' row-clicked' ] ? ' cursor:pointer' : ' '
309
351
},
352
+ sortingIconStyles () {
353
+ return ! this .noSorting ? ' position-relative pr-4' : ' '
354
+ },
310
355
colspan () {
311
- return this .indexCol ? this .rawColumnNames .length + 1 : this .rawColumnNames .length
356
+ return this .indexColumn ? this .rawColumnNames .length + 1 : this .rawColumnNames .length
312
357
},
313
358
topLoadingPosition () {
314
359
const headerHeight = (this .filterRow ? 38 : 0 ) + ( this .small ? 32 + 4 : 46 + 7 )
@@ -318,32 +363,22 @@ export default {
318
363
const size = this .small ? ' 1.4rem' : this .currentItems .length === 1 ? ' 2rem' : ' 3rem'
319
364
return ` width:${ size} ;height:${ size} `
320
365
},
321
- iconStyles () {
322
- return ! this .noSorting ? ' position-relative pr-4' : ' '
323
- }
324
- // loadingStyles () {
325
- // return !this.loading ? '' :
326
- // `opacity: .4; ${this.loading === 'noEvents' ? 'pointer-events:none' : ''}`
327
- // }
366
+
328
367
},
329
368
watch: {
330
- // filter () { deep:true },
331
369
items (val , oldVal ) {
332
370
if (val .length !== oldVal .length || JSON .stringify (val) !== JSON .stringify (oldVal))
333
371
this .passedItems = val
372
+ },
373
+ totalPages: {
374
+ immediate: true ,
375
+ handler (val , oldVal ) {
376
+ if (val !== oldVal)
377
+ this .$emit (' pages-change' , val)
378
+ }
334
379
}
335
380
},
336
381
methods: {
337
- log (col ) {
338
- console .log (col)
339
- },
340
- checkPagination () {
341
- const pages = Math .ceil ((this .sortedItems .length )/ this .perPageItems ) || 1
342
- if (pages !== this .pages ){
343
- this .$emit (' pages-change' , pages)
344
- this .pages = pages
345
- }
346
- },
347
382
changeSort (name , index ) {
348
383
if (index && ! this .sortable (index))
349
384
return
@@ -354,9 +389,6 @@ export default {
354
389
this .sorter .direction = 0
355
390
this .sorter .name = name
356
391
},
357
- // setTableFilter (val) {
358
- // this.filter = val
359
- // },
360
392
addColumnFilter (colName , value ) {
361
393
this .$set (this .columnFilter , colName, value)
362
394
},
@@ -375,9 +407,6 @@ export default {
375
407
.map (word => word .charAt (0 ).toUpperCase () + word .slice (1 ))
376
408
.join (' ' )
377
409
},
378
- // rowClass (item) {
379
- // return item._classes ? item._classes : ''
380
- // },
381
410
cellClass (item , colName , index ) {
382
411
let classes = []
383
412
if (item ._cellClasses && item ._cellClasses [colName])
0 commit comments