NumericFilter.html
4.54 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-ux-grid-filter-NumericFilter'>/**
</span> * @class Ext.ux.grid.filter.NumericFilter
* @extends Ext.ux.grid.filter.Filter
* Filters using an Ext.ux.grid.menu.RangeMenu.
* <p><b><u>Example Usage:</u></b></p>
* <pre><code>
var filters = Ext.create('Ext.ux.grid.GridFilters', {
...
filters: [{
type: 'numeric',
dataIndex: 'price'
}]
});
* </code></pre>
* <p>Any of the configuration options for {@link Ext.ux.grid.menu.RangeMenu} can also be specified as
* configurations to NumericFilter, and will be copied over to the internal menu instance automatically.</p>
*/
Ext.define('Ext.ux.grid.filter.NumericFilter', {
extend: 'Ext.ux.grid.filter.Filter',
alias: 'gridfilter.numeric',
uses: ['Ext.form.field.Number'],
<span id='Ext-ux-grid-filter-NumericFilter-method-createMenu'> /**
</span> * @private @override
* Creates the Menu for this filter.
* @param {Object} config Filter configuration
* @return {Ext.menu.Menu}
*/
createMenu: function(config) {
var me = this,
menu;
menu = Ext.create('Ext.ux.grid.menu.RangeMenu', config);
menu.on('update', me.fireUpdate, me);
return menu;
},
<span id='Ext-ux-grid-filter-NumericFilter-method-getValue'> /**
</span> * @private
* Template method that is to get and return the value of the filter.
* @return {String} The value of this filter
*/
getValue : function () {
return this.menu.getValue();
},
<span id='Ext-ux-grid-filter-NumericFilter-method-setValue'> /**
</span> * @private
* Template method that is to set the value of the filter.
* @param {Object} value The value to set the filter
*/
setValue : function (value) {
this.menu.setValue(value);
},
<span id='Ext-ux-grid-filter-NumericFilter-method-isActivatable'> /**
</span> * @private
* Template method that is to return <tt>true</tt> if the filter
* has enough configuration information to be activated.
* @return {Boolean}
*/
isActivatable : function () {
var values = this.getValue(),
key;
for (key in values) {
if (values[key] !== undefined) {
return true;
}
}
return false;
},
<span id='Ext-ux-grid-filter-NumericFilter-method-getSerialArgs'> /**
</span> * @private
* Template method that is to get and return serialized filter data for
* transmission to the server.
* @return {Object/Array} An object or collection of objects containing
* key value pairs representing the current configuration of the filter.
*/
getSerialArgs : function () {
var key,
args = [],
values = this.menu.getValue();
for (key in values) {
args.push({
type: 'numeric',
comparison: key,
value: values[key]
});
}
return args;
},
<span id='Ext-ux-grid-filter-NumericFilter-method-validateRecord'> /**
</span> * Template method that is to validate the provided Ext.data.Record
* against the filters configuration.
* @param {Ext.data.Record} record The record to validate
* @return {Boolean} true if the record is valid within the bounds
* of the filter, false otherwise.
*/
validateRecord : function (record) {
var val = record.get(this.dataIndex),
values = this.getValue(),
isNumber = Ext.isNumber;
if (isNumber(values.eq) && val != values.eq) {
return false;
}
if (isNumber(values.lt) && val >= values.lt) {
return false;
}
if (isNumber(values.gt) && val <= values.gt) {
return false;
}
return true;
}
});
</pre>
</body>
</html>