Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / StringFilter.html
1 <html>
2 <head>
3   <title>The source code</title>
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
6 </head>
7 <body  onload="prettyPrint();">
8     <pre class="prettyprint lang-js"><div id="cls-Ext.ux.grid.filter.StringFilter"></div>/** \r
9  * @class Ext.ux.grid.filter.StringFilter\r
10  * @extends Ext.ux.grid.filter.Filter\r
11  * Filter by a configurable Ext.form.TextField\r
12  * <p><b><u>Example Usage:</u></b></p>\r
13  * <pre><code>    \r
14 var filters = new Ext.ux.grid.GridFilters({\r
15     ...\r
16     filters: [{\r
17         // required configs\r
18         type: 'string',\r
19         dataIndex: 'name',\r
20         \r
21         // optional configs\r
22         value: 'foo',\r
23         active: true, // default is false\r
24         iconCls: 'ux-gridfilter-text-icon' // default\r
25         // any Ext.form.TextField configs accepted\r
26     }]\r
27 });\r
28  * </code></pre>\r
29  */\r
30 Ext.ux.grid.filter.StringFilter = Ext.extend(Ext.ux.grid.filter.Filter, {\r
31 \r
32     <div id="cfg-Ext.ux.grid.filter.StringFilter-iconCls"></div>/**\r
33      * @cfg {String} iconCls\r
34      * The iconCls to be applied to the menu item.\r
35      * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.\r
36      */\r
37     iconCls : 'ux-gridfilter-text-icon',\r
38 \r
39     emptyText: 'Enter Filter Text...',\r
40     selectOnFocus: true,\r
41     width: 125,\r
42     \r
43     /**  \r
44      * @private\r
45      * Template method that is to initialize the filter and install required menu items.\r
46      */\r
47     init : function (config) {\r
48         Ext.applyIf(config, {\r
49             enableKeyEvents: true,\r
50             iconCls: this.iconCls,\r
51             listeners: {\r
52                 scope: this,\r
53                 keyup: this.onInputKeyUp\r
54             }\r
55         });\r
56 \r
57         this.inputItem = new Ext.form.TextField(config); \r
58         this.menu.add(this.inputItem);\r
59         this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);\r
60     },\r
61     \r
62     /**\r
63      * @private\r
64      * Template method that is to get and return the value of the filter.\r
65      * @return {String} The value of this filter\r
66      */\r
67     getValue : function () {\r
68         return this.inputItem.getValue();\r
69     },\r
70     \r
71     /**\r
72      * @private\r
73      * Template method that is to set the value of the filter.\r
74      * @param {Object} value The value to set the filter\r
75      */ \r
76     setValue : function (value) {\r
77         this.inputItem.setValue(value);\r
78         this.fireEvent('update', this);\r
79     },\r
80 \r
81     /**\r
82      * @private\r
83      * Template method that is to return <tt>true</tt> if the filter\r
84      * has enough configuration information to be activated.\r
85      * @return {Boolean}\r
86      */\r
87     isActivatable : function () {\r
88         return this.inputItem.getValue().length > 0;\r
89     },\r
90 \r
91     /**\r
92      * @private\r
93      * Template method that is to get and return serialized filter data for\r
94      * transmission to the server.\r
95      * @return {Object/Array} An object or collection of objects containing\r
96      * key value pairs representing the current configuration of the filter.\r
97      */\r
98     getSerialArgs : function () {\r
99         return {type: 'string', value: this.getValue()};\r
100     },\r
101 \r
102     <div id="method-Ext.ux.grid.filter.StringFilter-validateRecord"></div>/**\r
103      * Template method that is to validate the provided Ext.data.Record\r
104      * against the filters configuration.\r
105      * @param {Ext.data.Record} record The record to validate\r
106      * @return {Boolean} true if the record is valid within the bounds\r
107      * of the filter, false otherwise.\r
108      */\r
109     validateRecord : function (record) {\r
110         var val = record.get(this.dataIndex);\r
111 \r
112         if(typeof val != 'string') {\r
113             return (this.getValue().length === 0);\r
114         }\r
115 \r
116         return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;\r
117     },\r
118     \r
119     /**  \r
120      * @private\r
121      * Handler method called when there is a keyup event on this.inputItem\r
122      */\r
123     onInputKeyUp : function (field, e) {\r
124         var k = e.getKey();\r
125         if (k == e.RETURN && field.isValid()) {\r
126             e.stopEvent();\r
127             this.menu.hide(true);\r
128             return;\r
129         }\r
130         // restart the timer\r
131         this.updateTask.delay(this.updateBuffer);\r
132     }\r
133 });\r
134 </pre>
135 </body>
136 </html>