-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathVuetablePaginationMixin.vue
88 lines (86 loc) · 1.97 KB
/
VuetablePaginationMixin.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
<script>
import CssSemanticUI from './VuetableCssSemanticUI.js'
export default {
props: {
css: {
type: Object,
default () {
return {}
}
},
onEachSide: {
type: Number,
default () {
return 2
}
},
firstPage: {
type: Number,
default: 1
}
},
data: function() {
return {
eventPrefix: 'vuetable-pagination:',
tablePagination: null,
$_css: {}
}
},
computed: {
totalPage () {
return this.tablePagination === null
? 0
: this.last_page - this.firstPage + 1
},
lastPage () {
return this.tablePagination === null
? 0
: this.tablePagination.last_page
},
isOnFirstPage () {
return this.tablePagination === null
? false
: this.tablePagination.current_page === this.firstPage
},
isOnLastPage () {
return this.tablePagination === null
? false
: this.tablePagination.current_page === this.lastPage
},
notEnoughPages () {
return this.totalPage < (this.onEachSide * 2) + 4
},
windowSize () {
return this.onEachSide * 2 +1;
},
windowStart () {
if (!this.tablePagination || this.tablePagination.current_page <= this.onEachSide) {
return 1
} else if (this.tablePagination.current_page >= (this.totalPage - this.onEachSide)) {
return this.totalPage - this.onEachSide * 2
}
return this.tablePagination.current_page - this.onEachSide
},
},
created () {
this.mergeCss()
},
methods: {
mergeCss () {
this.$_css = {...CssSemanticUI.pagination, ...this.css}
},
loadPage (page) {
this.$emit(this.eventPrefix + 'change-page', page)
},
isCurrentPage (page) {
return page === this.tablePagination.current_page
},
setPaginationData (tablePagination) {
this.tablePagination = tablePagination
},
resetData () {
this.tablePagination = null
}
}
}
</script>