3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.ux.grid.filter.ListFilter
\r
9 * @extends Ext.ux.grid.filter.Filter
\r
10 * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load
\r
11 * their options the first time they are shown. ListFilter utilizes the
\r
12 * {@link Ext.ux.menu.ListMenu} component.</p>
\r
13 * <p>Although not shown here, this class accepts all configuration options
\r
14 * for {@link Ext.ux.menu.ListMenu}.</p>
\r
16 * <p><b><u>Example Usage:</u></b></p>
\r
18 var filters = new Ext.ux.grid.GridFilters({
\r
24 // options will be used as data to implicitly creates an ArrayStore
\r
25 options: ['extra small', 'small', 'medium', 'large', 'extra large']
\r
31 Ext.ux.grid.filter.ListFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
\r
34 * @cfg {Array} options
\r
35 * <p><code>data</code> to be used to implicitly create a data store
\r
36 * to back this list when the data source is <b>local</b>. If the
\r
37 * data for the list is remote, use the <code>{@link #store}</code>
\r
38 * config instead.</p>
\r
39 * <br><p>Each item within the provided array may be in one of the
\r
40 * following formats:</p>
\r
41 * <div class="mdetail-params"><ul>
\r
42 * <li><b>Array</b> :
\r
45 [11, 'extra small'],
\r
53 * <li><b>Object</b> :
\r
55 labelField: 'name', // override default of 'text'
\r
57 {id: 11, name:'extra small'},
\r
58 {id: 18, name:'small'},
\r
59 {id: 22, name:'medium'},
\r
60 {id: 35, name:'large'},
\r
61 {id: 44, name:'extra large'}
\r
65 * <li><b>String</b> :
\r
67 * options: ['extra small', 'small', 'medium', 'large', 'extra large']
\r
72 * @cfg {Boolean} phpMode
\r
73 * <p>Adjust the format of this filter. Defaults to false.</p>
\r
74 * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>
\r
76 // phpMode == false (default):
\r
77 filter[0][data][type] list
\r
78 filter[0][data][value] value1
\r
79 filter[0][data][value] value2
\r
80 filter[0][field] prod
\r
83 filter[0][data][type] list
\r
84 filter[0][data][value] value1, value2
\r
85 filter[0][field] prod
\r
87 * When GridFilters <code>@cfg encode = true</code>:
\r
89 // phpMode == false (default):
\r
90 filter : [{"type":"list","value":["small","medium"],"field":"size"}]
\r
93 filter : [{"type":"list","value":"small,medium","field":"size"}]
\r
98 * @cfg {Ext.data.Store} store
\r
99 * The {@link Ext.data.Store} this list should use as its data source
\r
100 * when the data source is <b>remote</b>. If the data for the list
\r
101 * is local, use the <code>{@link #options}</code> config instead.
\r
106 * Template method that is to initialize the filter and install required menu items.
\r
107 * @param {Object} config
\r
109 init : function (config) {
\r
110 this.dt = new Ext.util.DelayedTask(this.fireUpdate, this);
\r
112 // if a menu already existed, do clean up first
\r
114 this.menu.destroy();
\r
116 this.menu = new Ext.ux.menu.ListMenu(config);
\r
117 this.menu.on('checkchange', this.onCheckChange, this);
\r
122 * Template method that is to get and return the value of the filter.
\r
123 * @return {String} The value of this filter
\r
125 getValue : function () {
\r
126 return this.menu.getSelected();
\r
130 * Template method that is to set the value of the filter.
\r
131 * @param {Object} value The value to set the filter
\r
133 setValue : function (value) {
\r
134 this.menu.setSelected(value);
\r
135 this.fireEvent('update', this);
\r
140 * Template method that is to return <tt>true</tt> if the filter
\r
141 * has enough configuration information to be activated.
\r
142 * @return {Boolean}
\r
144 isActivatable : function () {
\r
145 return this.getValue().length > 0;
\r
150 * Template method that is to get and return serialized filter data for
\r
151 * transmission to the server.
\r
152 * @return {Object/Array} An object or collection of objects containing
\r
153 * key value pairs representing the current configuration of the filter.
\r
155 getSerialArgs : function () {
\r
156 var args = {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
\r
161 onCheckChange : function(){
\r
162 this.dt.delay(this.updateBuffer);
\r
167 * Template method that is to validate the provided Ext.data.Record
\r
168 * against the filters configuration.
\r
169 * @param {Ext.data.Record} record The record to validate
\r
170 * @return {Boolean} true if the record is valid within the bounds
\r
171 * of the filter, false otherwise.
\r
173 validateRecord : function (record) {
\r
174 return this.getValue().indexOf(record.get(this.dataIndex)) > -1;
\r