3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.ux.grid.filter.ListFilter
17 * @extends Ext.ux.grid.filter.Filter
18 * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load
19 * their options the first time they are shown. ListFilter utilizes the
20 * {@link Ext.ux.grid.menu.ListMenu} component.</p>
21 * <p>Although not shown here, this class accepts all configuration options
22 * for {@link Ext.ux.grid.menu.ListMenu}.</p>
24 * <p><b><u>Example Usage:</u></b></p>
26 var filters = Ext.create('Ext.ux.grid.GridFilters', {
32 // options will be used as data to implicitly creates an ArrayStore
33 options: ['extra small', 'small', 'medium', 'large', 'extra large']
39 Ext.define('Ext.ux.grid.filter.ListFilter', {
40 extend: 'Ext.ux.grid.filter.Filter',
41 alias: 'gridfilter.list',
44 * @cfg {Array} options
45 * <p><code>data</code> to be used to implicitly create a data store
46 * to back this list when the data source is <b>local</b>. If the
47 * data for the list is remote, use the <code>{@link #store}</code>
49 * <br><p>Each item within the provided array may be in one of the
50 * following formats:</p>
51 * <div class="mdetail-params"><ul>
65 labelField: 'name', // override default of 'text'
67 {id: 11, name:'extra small'},
68 {id: 18, name:'small'},
69 {id: 22, name:'medium'},
70 {id: 35, name:'large'},
71 {id: 44, name:'extra large'}
77 * options: ['extra small', 'small', 'medium', 'large', 'extra large']
82 * @cfg {Boolean} phpMode
83 * <p>Adjust the format of this filter. Defaults to false.</p>
84 * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>
86 // phpMode == false (default):
87 filter[0][data][type] list
88 filter[0][data][value] value1
89 filter[0][data][value] value2
93 filter[0][data][type] list
94 filter[0][data][value] value1, value2
97 * When GridFilters <code>@cfg encode = true</code>:
99 // phpMode == false (default):
100 filter : [{"type":"list","value":["small","medium"],"field":"size"}]
103 filter : [{"type":"list","value":"small,medium","field":"size"}]
108 * @cfg {Ext.data.Store} store
109 * The {@link Ext.data.Store} this list should use as its data source
110 * when the data source is <b>remote</b>. If the data for the list
111 * is local, use the <code>{@link #options}</code> config instead.
116 * Template method that is to initialize the filter.
117 * @param {Object} config
119 init : function (config) {
120 this.dt = Ext.create('Ext.util.DelayedTask', this.fireUpdate, this);
125 * Creates the Menu for this filter.
126 * @param {Object} config Filter configuration
127 * @return {Ext.menu.Menu}
129 createMenu: function(config) {
130 var menu = Ext.create('Ext.ux.grid.menu.ListMenu', config);
131 menu.on('checkchange', this.onCheckChange, this);
137 * Template method that is to get and return the value of the filter.
138 * @return {String} The value of this filter
140 getValue : function () {
141 return this.menu.getSelected();
145 * Template method that is to set the value of the filter.
146 * @param {Object} value The value to set the filter
148 setValue : function (value) {
149 this.menu.setSelected(value);
150 this.fireEvent('update', this);
155 * Template method that is to return <tt>true</tt> if the filter
156 * has enough configuration information to be activated.
159 isActivatable : function () {
160 return this.getValue().length > 0;
165 * Template method that is to get and return serialized filter data for
166 * transmission to the server.
167 * @return {Object/Array} An object or collection of objects containing
168 * key value pairs representing the current configuration of the filter.
170 getSerialArgs : function () {
171 return {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
175 onCheckChange : function(){
176 this.dt.delay(this.updateBuffer);
181 * Template method that is to validate the provided Ext.data.Record
182 * against the filters configuration.
183 * @param {Ext.data.Record} record The record to validate
184 * @return {Boolean} true if the record is valid within the bounds
185 * of the filter, false otherwise.
187 validateRecord : function (record) {
188 var valuesArray = this.getValue();
189 return Ext.Array.indexOf(valuesArray, record.get(this.dataIndex)) > -1;