2 * @class Ext.ux.grid.filter.ListFilter
3 * @extends Ext.ux.grid.filter.Filter
4 * <p>List filters are able to be preloaded/backed by an Ext.data.Store to load
5 * their options the first time they are shown. ListFilter utilizes the
6 * {@link Ext.ux.grid.menu.ListMenu} component.</p>
7 * <p>Although not shown here, this class accepts all configuration options
8 * for {@link Ext.ux.grid.menu.ListMenu}.</p>
10 * <p><b><u>Example Usage:</u></b></p>
12 var filters = Ext.create('Ext.ux.grid.GridFilters', {
18 // options will be used as data to implicitly creates an ArrayStore
19 options: ['extra small', 'small', 'medium', 'large', 'extra large']
25 Ext.define('Ext.ux.grid.filter.ListFilter', {
26 extend: 'Ext.ux.grid.filter.Filter',
27 alias: 'gridfilter.list',
30 * @cfg {Array} options
31 * <p><code>data</code> to be used to implicitly create a data store
32 * to back this list when the data source is <b>local</b>. If the
33 * data for the list is remote, use the <code>{@link #store}</code>
35 * <br><p>Each item within the provided array may be in one of the
36 * following formats:</p>
37 * <div class="mdetail-params"><ul>
51 labelField: 'name', // override default of 'text'
53 {id: 11, name:'extra small'},
54 {id: 18, name:'small'},
55 {id: 22, name:'medium'},
56 {id: 35, name:'large'},
57 {id: 44, name:'extra large'}
63 * options: ['extra small', 'small', 'medium', 'large', 'extra large']
68 * @cfg {Boolean} phpMode
69 * <p>Adjust the format of this filter. Defaults to false.</p>
70 * <br><p>When GridFilters <code>@cfg encode = false</code> (default):</p>
72 // phpMode == false (default):
73 filter[0][data][type] list
74 filter[0][data][value] value1
75 filter[0][data][value] value2
79 filter[0][data][type] list
80 filter[0][data][value] value1, value2
83 * When GridFilters <code>@cfg encode = true</code>:
85 // phpMode == false (default):
86 filter : [{"type":"list","value":["small","medium"],"field":"size"}]
89 filter : [{"type":"list","value":"small,medium","field":"size"}]
94 * @cfg {Ext.data.Store} store
95 * The {@link Ext.data.Store} this list should use as its data source
96 * when the data source is <b>remote</b>. If the data for the list
97 * is local, use the <code>{@link #options}</code> config instead.
102 * Template method that is to initialize the filter.
103 * @param {Object} config
105 init : function (config) {
106 this.dt = Ext.create('Ext.util.DelayedTask', this.fireUpdate, this);
111 * Creates the Menu for this filter.
112 * @param {Object} config Filter configuration
113 * @return {Ext.menu.Menu}
115 createMenu: function(config) {
116 var menu = Ext.create('Ext.ux.grid.menu.ListMenu', config);
117 menu.on('checkchange', this.onCheckChange, this);
123 * Template method that is to get and return the value of the filter.
124 * @return {String} The value of this filter
126 getValue : function () {
127 return this.menu.getSelected();
131 * Template method that is to set the value of the filter.
132 * @param {Object} value The value to set the filter
134 setValue : function (value) {
135 this.menu.setSelected(value);
136 this.fireEvent('update', this);
141 * Template method that is to return <tt>true</tt> if the filter
142 * has enough configuration information to be activated.
145 isActivatable : function () {
146 return this.getValue().length > 0;
151 * Template method that is to get and return serialized filter data for
152 * transmission to the server.
153 * @return {Object/Array} An object or collection of objects containing
154 * key value pairs representing the current configuration of the filter.
156 getSerialArgs : function () {
157 return {type: 'list', value: this.phpMode ? this.getValue().join(',') : this.getValue()};
161 onCheckChange : function(){
162 this.dt.delay(this.updateBuffer);
167 * Template method that is to validate the provided Ext.data.Record
168 * against the filters configuration.
169 * @param {Ext.data.Record} record The record to validate
170 * @return {Boolean} true if the record is valid within the bounds
171 * of the filter, false otherwise.
173 validateRecord : function (record) {
174 var valuesArray = this.getValue();
175 return Ext.Array.indexOf(valuesArray, record.get(this.dataIndex)) > -1;