8
8
:key ="'header--'+attribute" , :class ="headerClass(attribute)" ,
9
9
@click.self ="onHeaderClick(attribute, $event)" , @contextmenu.prevent ="openMenu" ) {{ attribute | capitalize }}
10
10
dg-filter( v-if ="filterables.includes(attribute)" , :isActive ="activefilterables[attribute]" ,
11
- @change ="onFilterMenuChange(attribute, $event)" , @sort ="onSort(attribute, $event)" )
11
+ :bound ="filterBounds[attribute]" , :range ="filterRanges[attribute]" ,
12
+ @change ="onFilterMenuChange(attribute, $event)" , @sort ="onSort(attribute, $event)" , @range ="onRange(attribute, $event)" )
12
13
tbody
13
14
transition-group( v-for ="(record, index) in sortedRecords" , name ="fade" , tag ="tr" )
14
15
td.cell.cell--date ( v-if ="isfirstOfDateGroup(index)" , key ="cell-date" , :rowspan ="getNumOfDateGroupByIndex(index)" )
@@ -33,7 +34,7 @@ import _ from 'lodash'
33
34
import { TweenMax , Linear } from ' gsap'
34
35
import { records } from ' ../data.json'
35
36
import settings from ' ../tableSettings'
36
- import { toCurrency , toMMMMYYYY , capitalize , toGMapQuery } from ' utils/filters'
37
+ import { toCurrency , toMMMMYYYY , capitalize , toGMapQuery , toUpperMagnitude } from ' utils/filters'
37
38
import { offsets } from ' utils/mouse'
38
39
import DgMenu from ' components/DgMenu'
39
40
import DgCellMenu from ' components/DgCellMenu'
@@ -53,10 +54,16 @@ export default {
53
54
},
54
55
data () {
55
56
let sortOrders = {}
57
+ let filterRanges = {}
58
+ let filterBounds = {}
56
59
let activefilterables = {}
57
60
settings .filterables .forEach ((attribute ) => {
58
- sortOrders[attribute] = 0
59
61
activefilterables[attribute] = false
62
+ sortOrders[attribute] = 0
63
+ filterBounds[attribute] = [0 , toUpperMagnitude (records .reduce ((acc , cur ) => {
64
+ return cur[attribute] > acc ? cur[attribute] : acc
65
+ }, 0 ))]
66
+ filterRanges[attribute] = _ .clone (filterBounds[attribute])
60
67
})
61
68
return {
62
69
records: records,
@@ -69,6 +76,8 @@ export default {
69
76
omitOnMenu: settings .omitOnMenu ,
70
77
sortAttribute: ' ' ,
71
78
sortOrders: sortOrders,
79
+ filterRanges: filterRanges,
80
+ filterBounds: filterBounds,
72
81
activefilterables: activefilterables,
73
82
expanding: ' ' ,
74
83
focusCell: {
@@ -85,10 +94,19 @@ export default {
85
94
},
86
95
computed: {
87
96
sortedRecords () {
88
- let {sortAttribute, sortOrders, records} = this
97
+ const {sortAttribute , sortOrders , filterRanges , records } = this
89
98
const order = sortOrders[sortAttribute] || 0
99
+
100
+ // Filtered fitted in ranges records
101
+ const filteredRecords = records .filter ((record ) => {
102
+ return Object .keys (filterRanges).reduce ((acc , key ) => {
103
+ return filterRanges[key][0 ] <= record[key] && filterRanges[key][1 ] >= record[key]
104
+ }, true )
105
+ })
106
+
90
107
if (sortAttribute) {
91
- return records .slice ().sort ((a , b ) => {
108
+ // Sort by sortAttribute locally and by date globally
109
+ return filteredRecords .slice ().sort ((a , b ) => {
92
110
const aSort = a[sortAttribute]
93
111
const bSort = b[sortAttribute]
94
112
const localOrder = (aSort === bSort ? 0 : aSort > bSort ? 1 : - 1 ) * order
@@ -97,7 +115,8 @@ export default {
97
115
return moment (aDate).isSame (bDate) ? localOrder : moment (aDate).isBefore (bDate) ? - 1 : 1
98
116
})
99
117
} else {
100
- return records .slice ().sort ((a , b ) => {
118
+ // Only sort by date
119
+ return filteredRecords .slice ().sort ((a , b ) => {
101
120
return moment (a .date ).isBefore (b .date ) ? - 1 : 1
102
121
})
103
122
}
@@ -212,7 +231,11 @@ export default {
212
231
this .sortAttribute = order ? attribute : ' '
213
232
this .sortOrders [attribute] = order
214
233
},
234
+ onRange (attribute , range ) {
235
+ this .filterRanges [attribute] = range
236
+ },
215
237
onFilterMenuChange (attribute , active ) {
238
+ this .clearFocusCell ()
216
239
this .activefilterables [attribute] = active
217
240
}
218
241
}
0 commit comments