-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathMyVuetable.vue
More file actions
120 lines (118 loc) · 3.36 KB
/
MyVuetable.vue
File metadata and controls
120 lines (118 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<template>
<div class="ui container">
<filter-bar></filter-bar>
<vuetable ref="vuetable"
:api-url="apiUrl"
:fields="fields"
pagination-path=""
:per-page="10"
:multi-sort="true"
:sort-order="sortOrder"
:append-params="appendParams"
detail-row-component="detailRowComponent"
@vuetable:cell-clicked="onCellClicked"
@vuetable:pagination-data="onPaginationData"
>
<template :slot="slotName" scope="props" v-for="slotName in $scopedSlots?Object.keys($scopedSlots):null" >
<slot :name="slotName" :row-data="props.rowData" :row-index="props.rowIndex" :row-field="props.rowField"></slot>
</template>
</vuetable>
<div class="vuetable-pagination ui basic segment grid">
<vuetable-pagination-info ref="paginationInfo"
></vuetable-pagination-info>
<vuetable-pagination ref="pagination"
@vuetable-pagination:change-page="onChangePage"
></vuetable-pagination>
</div>
</div>
</template>
<script>
import accounting from 'accounting'
import moment from 'moment'
import Vue from 'vue'
import VueEvents from 'vue-events'
import Vuetable from 'vuetable-2/src/components/Vuetable'
import VuetablePagination from 'vuetable-2/src/components/VuetablePagination'
import VuetablePaginationInfo from 'vuetable-2/src/components/VuetablePaginationInfo'
import CustomActions from './CustomActions'
import FilterBar from './FilterBar'
Vue.use(VueEvents)
Vue.component('custom-actions', CustomActions)
Vue.component('filter-bar', FilterBar)
export default {
components: {
Vuetable,
VuetablePagination,
VuetablePaginationInfo
},
props: {
apiUrl: {
type: String,
required: true
},
fields: {
type: Array,
required: true
},
sortOrder: {
type: Array,
default() {
return []
}
},
appendParams: {
type: Object,
default() {
return {}
}
},
detailRowComponent: {
type: String
}
},
data () {
return {}
},
mounted () {
this.$events.$on('filter-set', eventData => this.onFilterSet(eventData))
this.$events.$on('filter-reset', e => this.onFilterReset())
},
methods: {
allcap (value) {
return value.toUpperCase()
},
genderLabel (value) {
return value === 'M'
? '<span class="ui teal label"><i class="large man icon"></i>Male</span>'
: '<span class="ui pink label"><i class="large woman icon"></i>Female</span>'
},
formatNumber (value) {
return accounting.formatNumber(value, 2)
},
formatDate (value, fmt = 'D MMM YYYY') {
return (value == null)
? ''
: moment(value, 'YYYY-MM-DD').format(fmt)
},
onPaginationData (paginationData) {
this.$refs.pagination.setPaginationData(paginationData)
this.$refs.paginationInfo.setPaginationData(paginationData)
},
onChangePage (page) {
this.$refs.vuetable.changePage(page)
},
onCellClicked (data, field, event) {
console.log('cellClicked: ', field.name)
this.$refs.vuetable.toggleDetailRow(data.id)
},
onFilterSet (filterText) {
this.appendParams.filter = filterText
Vue.nextTick( () => this.$refs.vuetable.refresh() )
},
onFilterReset () {
delete this.appendParams.filter
Vue.nextTick( () => this.$refs.vuetable.refresh() )
}
}
}
</script>