-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtable-column-header.vue
91 lines (90 loc) · 1.88 KB
/
table-column-header.vue
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
<template>
<th :class="[
column.align ? `is-${column.align}`: '',
isAscending ? 'ascending' : '',
isDescending ? 'descending' : '',
]" ref="elColumn"
@click="handleClick"
>
<div class="cell">{{column.label}} <span class="caret-wrapper" v-if="isSortCell"><i class="sort-caret ascending"></i><i class="sort-caret descending"></i></span></div>
</th>
</template>
<script>
export default {
name: 'snb-table-column-header',
props: {
column: {
type: Object,
default: () => {}
},
sort: {
type: Object,
default: () => {}
},
// isFixedCell: {
// type: Boolean,
// default: false
// },
},
data () {
return {
};
},
computed: {
isSortCell () {
if (!this.sort) return false;
return this.column.sortable ||
this.sort.prop === this.column.prop ||
this.sort.defaultProp === this.column.prop;
},
isAscending () {
return this.sort && this.sort.prop === this.column.prop && this.sort.order === 'asc';
},
isDescending () {
return this.sort && this.sort.prop === this.column.prop && this.sort.order === 'desc';
}
},
created() {
},
mounted () {
},
methods: {
handleClick () {
if (this.isSortCell) {
this.$emit('handleHeadSortClick', this.column);
}
}
}
};
</script>
<style lang="stylus">
.caret-wrapper
position relative
display inline-flex
flex-direction column
align-items center
width 12px
height 22px
vertical-align middle
overflow hidden
.sort-caret
position absolute
left 1px
width 0
height 0
border 5px solid transparent
&.ascending
border-bottom-color #c0c4cc
top 0px
&.descending
border-top-color #c0c4cc
bottom 0px
th.ascending
.sort-caret
&.ascending
border-bottom-color #f75b5b
th.descending
.sort-caret
&.descending
border-top-color #6282fb
</style>