]> git.proxmox.com Git - extjs.git/blame - extjs/classic/classic/src/grid/filters/filter/Boolean.js
add extjs 6.0.1 sources
[extjs.git] / extjs / classic / classic / src / grid / filters / filter / Boolean.js
CommitLineData
6527f429
DM
1/**\r
2 * The boolean grid filter allows you to create a filter selection that limits results\r
3 * to values matching true or false. The filter can be set programmatically or via \r
4 * user input with a configurable {@link Ext.form.field.Radio radio field} in the filter section \r
5 * of the column header.\r
6 * \r
7 * Boolean filters use unique radio group IDs, so you may utilize more than one.\r
8 *\r
9 * Example Boolean Filter Usage:\r
10 * \r
11 * @example\r
12 * var shows = Ext.create('Ext.data.Store', {\r
13 * fields: ['id','show', 'visible'],\r
14 * data: [\r
15 * {id: 0, show: 'Battlestar Galactica', visible: true},\r
16 * {id: 1, show: 'Doctor Who', visible: true},\r
17 * {id: 2, show: 'Farscape', visible: false},\r
18 * {id: 3, show: 'Firefly', visible: true},\r
19 * {id: 4, show: 'Star Trek', visible: true},\r
20 * {id: 5, show: 'Star Wars: Christmas Special', visible: false}\r
21 * ]\r
22 * });\r
23 * \r
24 * Ext.create('Ext.grid.Panel', {\r
25 * renderTo: Ext.getBody(),\r
26 * title: 'Sci-Fi Television',\r
27 * height: 250,\r
28 * width: 375,\r
29 * store: shows,\r
30 * plugins: 'gridfilters',\r
31 * columns: [{\r
32 * dataIndex: 'id',\r
33 * text: 'ID',\r
34 * width: 50\r
35 * },{\r
36 * dataIndex: 'show',\r
37 * text: 'Show',\r
38 * flex: 1 \r
39 * },{\r
40 * dataIndex: 'visible',\r
41 * text: 'Visibility',\r
42 * width: 125,\r
43 * filter: {\r
44 * type: 'boolean',\r
45 * value: 'true',\r
46 * yesText: 'True',\r
47 * noText: 'False'\r
48 * }\r
49 * }]\r
50 * }); \r
51 */\r
52Ext.define('Ext.grid.filters.filter.Boolean', {\r
53 extend: 'Ext.grid.filters.filter.SingleFilter',\r
54 alias: 'grid.filter.boolean',\r
55\r
56 type: 'boolean',\r
57\r
58 operator: '=',\r
59\r
60 /**\r
61 * @cfg {Boolean} defaultValue\r
62 * Set this to null if you do not want either option to be checked by default. Defaults to false.\r
63 */\r
64 defaultValue: false,\r
65\r
66 //<locale>\r
67 /**\r
68 * @cfg {String} yesText\r
69 * Defaults to 'Yes'.\r
70 */\r
71 yesText: 'Yes',\r
72 //</locale>\r
73\r
74 //<locale>\r
75 /**\r
76 * @cfg {String} noText\r
77 * Defaults to 'No'.\r
78 */\r
79 noText: 'No',\r
80 //</locale>\r
81\r
82 updateBuffer: 0,\r
83\r
84 /**\r
85 * @private\r
86 * Template method that is to initialize the filter and install required menu items.\r
87 */\r
88 createMenu: function (config) {\r
89 var me = this,\r
90 gId = Ext.id(),\r
91 listeners = {\r
92 scope: me,\r
93 click: me.onClick\r
94 },\r
95 itemDefaults = me.getItemDefaults();\r
96\r
97 me.callParent(arguments);\r
98\r
99 me.menu.add([Ext.apply({\r
100 text: me.yesText,\r
101 filterKey: 1,\r
102 group: gId,\r
103 checked: !!me.defaultValue,\r
104 listeners: listeners\r
105 }, itemDefaults), Ext.apply({\r
106 text: me.noText,\r
107 filterKey: 0,\r
108 group: gId,\r
109 checked: !me.defaultValue,\r
110 listeners: listeners\r
111 }, itemDefaults)]);\r
112 },\r
113\r
114 /**\r
115 * @private\r
116 */\r
117 onClick: function (field) {\r
118 this.setValue(!!field.filterKey);\r
119 },\r
120\r
121 /**\r
122 * @private\r
123 * Template method that is to set the value of the filter.\r
124 * @param {Object} value The value to set the filter.\r
125 */\r
126 setValue: function (value) {\r
127 var me = this;\r
128\r
129 me.filter.setValue(value);\r
130\r
131 if (value !== undefined && me.active) {\r
132 me.value = value;\r
133 me.updateStoreFilter();\r
134 } else {\r
135 me.setActive(true);\r
136 }\r
137 },\r
138\r
139 // This is supposed to be just a stub.\r
140 activateMenu: Ext.emptyFn\r
141});\r