Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / BooleanFilter.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.BooleanFilter"></div>/** \r
9  * @class Ext.ux.grid.filter.BooleanFilter\r
10  * @extends Ext.ux.grid.filter.Filter\r
11  * Boolean filters use unique radio group IDs (so you can have more than one!)\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: 'boolean',\r
19         dataIndex: 'visible'\r
20 \r
21         // optional configs\r
22         defaultValue: null, // leave unselected (false selected by default)\r
23         yesText: 'Yes',     // default\r
24         noText: 'No'        // default\r
25     }]\r
26 });\r
27  * </code></pre>\r
28  */\r
29 Ext.ux.grid.filter.BooleanFilter = Ext.extend(Ext.ux.grid.filter.Filter, {\r
30         <div id="cfg-Ext.ux.grid.filter.BooleanFilter-defaultValue"></div>/**\r
31          * @cfg {Boolean} defaultValue\r
32          * Set this to null if you do not want either option to be checked by default. Defaults to false.\r
33          */\r
34         defaultValue : false,\r
35         <div id="cfg-Ext.ux.grid.filter.BooleanFilter-yesText"></div>/**\r
36          * @cfg {String} yesText\r
37          * Defaults to 'Yes'.\r
38          */\r
39         yesText : 'Yes',\r
40         <div id="cfg-Ext.ux.grid.filter.BooleanFilter-noText"></div>/**\r
41          * @cfg {String} noText\r
42          * Defaults to 'No'.\r
43          */\r
44         noText : 'No',\r
45 \r
46     /**  \r
47      * @private\r
48      * Template method that is to initialize the filter and install required menu items.\r
49      */\r
50     init : function (config) {\r
51         var gId = Ext.id();\r
52                 this.options = [\r
53                         new Ext.menu.CheckItem({text: this.yesText, group: gId, checked: this.defaultValue === true}),\r
54                         new Ext.menu.CheckItem({text: this.noText, group: gId, checked: this.defaultValue === false})];\r
55                 \r
56                 this.menu.add(this.options[0], this.options[1]);\r
57                 \r
58                 for(var i=0; i<this.options.length; i++){\r
59                         this.options[i].on('click', this.fireUpdate, this);\r
60                         this.options[i].on('checkchange', this.fireUpdate, this);\r
61                 }\r
62         },\r
63         \r
64     /**\r
65      * @private\r
66      * Template method that is to get and return the value of the filter.\r
67      * @return {String} The value of this filter\r
68      */\r
69     getValue : function () {\r
70                 return this.options[0].checked;\r
71         },\r
72 \r
73     /**\r
74      * @private\r
75      * Template method that is to set the value of the filter.\r
76      * @param {Object} value The value to set the filter\r
77      */ \r
78         setValue : function (value) {\r
79                 this.options[value ? 0 : 1].setChecked(true);\r
80         },\r
81 \r
82     /**\r
83      * @private\r
84      * Template method that is to get and return serialized filter data for\r
85      * transmission to the server.\r
86      * @return {Object/Array} An object or collection of objects containing\r
87      * key value pairs representing the current configuration of the filter.\r
88      */\r
89     getSerialArgs : function () {\r
90                 var args = {type: 'boolean', value: this.getValue()};\r
91                 return args;\r
92         },\r
93         \r
94     <div id="method-Ext.ux.grid.filter.BooleanFilter-validateRecord"></div>/**\r
95      * Template method that is to validate the provided Ext.data.Record\r
96      * against the filters configuration.\r
97      * @param {Ext.data.Record} record The record to validate\r
98      * @return {Boolean} true if the record is valid within the bounds\r
99      * of the filter, false otherwise.\r
100      */\r
101     validateRecord : function (record) {\r
102                 return record.get(this.dataIndex) == this.getValue();\r
103         }\r
104 });</pre>
105 </body>
106 </html>