This repository was archived by the owner on Apr 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathHeadSort.vue
More file actions
62 lines (62 loc) · 1.36 KB
/
HeadSort.vue
File metadata and controls
62 lines (62 loc) · 1.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
<template>
<a href="#" @click.prevent="handleClick" name="HeadSort" role="button" v-bind:aria-label="sortLabel">
<i :class="cls"></i>
</a>
</template>
<script>
/**
* Sorting arrows within <th>
*/
export default {
name: 'HeadSort',
props: {
field: { type: String, required: true },
query: { type: Object, required: true }
},
data: () => ({
order: ''
}),
computed: {
cls () {
const { order } = this
return [
'fa',
{ 'fa-sort text-muted': !order,
'fa-sort-up': order === 'asc',
'fa-sort-down': order === 'desc'
}
]
},
sortLabel() {
const { order } = this;
let key = 'Not sorted';
const nextOrder = this.getNextSortOrder();
if (nextOrder === 'asc') {
key = 'Sort ascending';
} else if (nextOrder === 'desc') {
key = 'Sort descending';
}
return this.$i18nForDatatable(key) + ' ' + this.field;
}
},
watch: {
query: {
handler ({ sort: field, order }) {
this.order = field === this.field ? order : ''
},
deep: true,
immediate: true
}
},
methods: {
getNextSortOrder () {
return this.order === 'desc' ? 'asc' : 'desc';
},
handleClick () {
const { query } = this
query.sort = this.field
query.order = this.getNextSortOrder();
}
}
}
</script>