sort-control-mixin.js
2.78 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
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
data: function data() {
return {
sortColumns: {}
};
},
methods: {
enableSort: function enableSort(val) {
return typeof val === 'string' ? true : false;
},
setSortColumns: function setSortColumns() {
var self = this,
sortColumns = {},
titleRowsToSortInfo = [];
if (self.internalTitleRows.length > 0) {
self.internalTitleRows.filter(function (row) {
row.filter(function (column, index) {
if (typeof column.orderBy === 'string' && column.fields.length === 1) {
column.field = column.fields[0];
titleRowsToSortInfo.push(column);
}
});
});
}
var collection = titleRowsToSortInfo.length > 0 ? titleRowsToSortInfo : self.internalColumns;
collection.filter(function (item, index) {
if (self.enableSort(item.orderBy)) {
sortColumns[item.field] = item.orderBy;
}
});
this.sortColumns = sortColumns;
this.singleSortInit();
},
getCurrentSort: function getCurrentSort(field) {
return this.sortColumns[field];
},
sortControl: function sortControl(field) {
var orderBy = this.sortColumns[field];
if (this.enableSort(orderBy)) {
if (this.sortAlways) {
this.sortColumns[field] = orderBy === 'asc' ? 'desc' : 'asc';
} else {
this.sortColumns[field] = orderBy === 'asc' ? 'desc' : this.sortColumns[field] === 'desc' ? '' : 'asc';
}
if (!this.multipleSort) {
for (var col in this.sortColumns) {
if (col !== field) {
this.sortColumns[col] = '';
}
}
}
this.$emit('sort-change', this.sortColumns);
}
},
singleSortInit: function singleSortInit() {
var self = this,
result = false;
if (!self.multipleSort && self.sortColumns) {
for (var col in self.sortColumns) {
if (result) {
self.sortColumns[col] = '';
}
result = true;
}
}
},
resetOrder: function resetOrder() {
this.setSortColumns();
this.$emit('sort-change', this.sortColumns);
}
}
};