Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / Filter.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">Ext.namespace('Ext.ux.grid.filter');\r
9 \r
10 <div id="cls-Ext.ux.grid.filter.Filter"></div>/** \r
11  * @class Ext.ux.grid.filter.Filter\r
12  * @extends Ext.util.Observable\r
13  * Abstract base class for filter implementations.\r
14  */\r
15 Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {\r
16     <div id="cfg-Ext.ux.grid.filter.Filter-active"></div>/**\r
17      * @cfg {Boolean} active\r
18      * Indicates the initial status of the filter (defaults to false).\r
19      */\r
20     active : false,\r
21     <div id="prop-Ext.ux.grid.filter.Filter-active"></div>/**\r
22      * True if this filter is active.  Use setActive() to alter after configuration.\r
23      * @type Boolean\r
24      * @property active\r
25      */\r
26     <div id="cfg-Ext.ux.grid.filter.Filter-dataIndex"></div>/**\r
27      * @cfg {String} dataIndex \r
28      * The {@link Ext.data.Store} dataIndex of the field this filter represents.\r
29      * The dataIndex does not actually have to exist in the store.\r
30      */\r
31     dataIndex : null,\r
32     <div id="prop-Ext.ux.grid.filter.Filter-menu"></div>/**\r
33      * The filter configuration menu that will be installed into the filter submenu of a column menu.\r
34      * @type Ext.menu.Menu\r
35      * @property\r
36      */\r
37     menu : null,\r
38     <div id="cfg-Ext.ux.grid.filter.Filter-updateBuffer"></div>/**\r
39      * @cfg {Number} updateBuffer\r
40      * Number of milliseconds to wait after user interaction to fire an update. Only supported \r
41      * by filters: 'list', 'numeric', and 'string'. Defaults to 500.\r
42      */\r
43     updateBuffer : 500,\r
44 \r
45     constructor : function (config) {\r
46         Ext.apply(this, config);\r
47             \r
48         this.addEvents(\r
49             <div id="event-Ext.ux.grid.filter.Filter-activate"></div>/**\r
50              * @event activate\r
51              * Fires when an inactive filter becomes active\r
52              * @param {Ext.ux.grid.filter.Filter} this\r
53              */\r
54             'activate',\r
55             <div id="event-Ext.ux.grid.filter.Filter-deactivate"></div>/**\r
56              * @event deactivate\r
57              * Fires when an active filter becomes inactive\r
58              * @param {Ext.ux.grid.filter.Filter} this\r
59              */\r
60             'deactivate',\r
61             <div id="event-Ext.ux.grid.filter.Filter-serialize"></div>/**\r
62              * @event serialize\r
63              * Fires after the serialization process. Use this to attach additional parameters to serialization\r
64              * data before it is encoded and sent to the server.\r
65              * @param {Array/Object} data A map or collection of maps representing the current filter configuration.\r
66              * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.\r
67              */\r
68             'serialize',\r
69             <div id="event-Ext.ux.grid.filter.Filter-update"></div>/**\r
70              * @event update\r
71              * Fires when a filter configuration has changed\r
72              * @param {Ext.ux.grid.filter.Filter} this The filter object.\r
73              */\r
74             'update'\r
75         );\r
76         Ext.ux.grid.filter.Filter.superclass.constructor.call(this);\r
77 \r
78         this.menu = new Ext.menu.Menu();\r
79         this.init(config);\r
80         if(config && config.value){\r
81             this.setValue(config.value);\r
82             this.setActive(config.active !== false, true);\r
83             delete config.value;\r
84         }\r
85     },\r
86 \r
87     <div id="method-Ext.ux.grid.filter.Filter-destroy"></div>/**\r
88      * Destroys this filter by purging any event listeners, and removing any menus.\r
89      */\r
90     destroy : function(){\r
91         if (this.menu){\r
92             this.menu.destroy();\r
93         }\r
94         this.purgeListeners();\r
95     },\r
96 \r
97     <div id="prop-Ext.ux.grid.filter.Filter-init"></div>/**\r
98      * Template method to be implemented by all subclasses that is to\r
99      * initialize the filter and install required menu items.\r
100      * Defaults to Ext.emptyFn.\r
101      */\r
102     init : Ext.emptyFn,\r
103     \r
104     <div id="method-Ext.ux.grid.filter.Filter-getValue"></div>/**\r
105      * Template method to be implemented by all subclasses that is to\r
106      * get and return the value of the filter.\r
107      * Defaults to Ext.emptyFn.\r
108      * @return {Object} The 'serialized' form of this filter\r
109      * @methodOf Ext.ux.grid.filter.Filter\r
110      */\r
111     getValue : Ext.emptyFn,\r
112     \r
113     <div id="method-Ext.ux.grid.filter.Filter-setValue"></div>/**\r
114      * Template method to be implemented by all subclasses that is to\r
115      * set the value of the filter and fire the 'update' event.\r
116      * Defaults to Ext.emptyFn.\r
117      * @param {Object} data The value to set the filter\r
118      * @methodOf Ext.ux.grid.filter.Filter\r
119      */ \r
120     setValue : Ext.emptyFn,\r
121     \r
122     <div id="method-Ext.ux.grid.filter.Filter-isActivatable"></div>/**\r
123      * Template method to be implemented by all subclasses that is to\r
124      * return <tt>true</tt> if the filter has enough configuration information to be activated.\r
125      * Defaults to <tt>return true</tt>.\r
126      * @return {Boolean}\r
127      */\r
128     isActivatable : function(){\r
129         return true;\r
130     },\r
131     \r
132     <div id="prop-Ext.ux.grid.filter.Filter-getSerialArgs"></div>/**\r
133      * Template method to be implemented by all subclasses that is to\r
134      * get and return serialized filter data for transmission to the server.\r
135      * Defaults to Ext.emptyFn.\r
136      */\r
137     getSerialArgs : Ext.emptyFn,\r
138 \r
139     <div id="method-Ext.ux.grid.filter.Filter-validateRecord"></div>/**\r
140      * Template method to be implemented by all subclasses that is to\r
141      * validates the provided Ext.data.Record against the filters configuration.\r
142      * Defaults to <tt>return true</tt>.\r
143      * @param {Ext.data.Record} record The record to validate\r
144      * @return {Boolean} true if the record is valid within the bounds\r
145      * of the filter, false otherwise.\r
146      */\r
147     validateRecord : function(){\r
148         return true;\r
149     },\r
150 \r
151     <div id="method-Ext.ux.grid.filter.Filter-serialize"></div>/**\r
152      * Returns the serialized filter data for transmission to the server\r
153      * and fires the 'serialize' event.\r
154      * @return {Object/Array} An object or collection of objects containing\r
155      * key value pairs representing the current configuration of the filter.\r
156      * @methodOf Ext.ux.grid.filter.Filter\r
157      */\r
158     serialize : function(){\r
159         var args = this.getSerialArgs();\r
160         this.fireEvent('serialize', args, this);\r
161         return args;\r
162     },\r
163 \r
164     /** @private */\r
165     fireUpdate : function(){\r
166         if (this.active) {\r
167             this.fireEvent('update', this);\r
168         }\r
169         this.setActive(this.isActivatable());\r
170     },\r
171     \r
172     <div id="method-Ext.ux.grid.filter.Filter-setActive"></div>/**\r
173      * Sets the status of the filter and fires the appropriate events.\r
174      * @param {Boolean} active        The new filter state.\r
175      * @param {Boolean} suppressEvent True to prevent events from being fired.\r
176      * @methodOf Ext.ux.grid.filter.Filter\r
177      */\r
178     setActive : function(active, suppressEvent){\r
179         if(this.active != active){\r
180             this.active = active;\r
181             if (suppressEvent !== true) {\r
182                 this.fireEvent(active ? 'activate' : 'deactivate', this);\r
183             }\r
184         }\r
185     }    \r
186 });</pre>
187 </body>
188 </html>