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.Filter
17 * @extends Ext.util.Observable
18 * Abstract base class for filter implementations.
20 Ext.define('Ext.ux.grid.filter.Filter', {
21 extend: 'Ext.util.Observable',
24 * @cfg {Boolean} active
25 * Indicates the initial status of the filter (defaults to false).
29 * True if this filter is active. Use setActive() to alter after configuration.
34 * @cfg {String} dataIndex
35 * The {@link Ext.data.Store} dataIndex of the field this filter represents.
36 * The dataIndex does not actually have to exist in the store.
40 * The filter configuration menu that will be installed into the filter submenu of a column menu.
46 * @cfg {Number} updateBuffer
47 * Number of milliseconds to wait after user interaction to fire an update. Only supported
48 * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
52 constructor : function (config) {
53 Ext.apply(this, config);
58 * Fires when an inactive filter becomes active
59 * @param {Ext.ux.grid.filter.Filter} this
64 * Fires when an active filter becomes inactive
65 * @param {Ext.ux.grid.filter.Filter} this
70 * Fires after the serialization process. Use this to attach additional parameters to serialization
71 * data before it is encoded and sent to the server.
72 * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
73 * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
78 * Fires when a filter configuration has changed
79 * @param {Ext.ux.grid.filter.Filter} this The filter object.
83 Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
85 this.menu = this.createMenu(config);
87 if(config && config.value){
88 this.setValue(config.value);
89 this.setActive(config.active !== false, true);
95 * Destroys this filter by purging any event listeners, and removing any menus.
101 this.clearListeners();
105 * Template method to be implemented by all subclasses that is to
106 * initialize the filter and install required menu items.
107 * Defaults to Ext.emptyFn.
113 * Creates the Menu for this filter.
114 * @param {Object} config Filter configuration
115 * @return {Ext.menu.Menu}
117 createMenu: function(config) {
118 return Ext.create('Ext.menu.Menu', config);
122 * Template method to be implemented by all subclasses that is to
123 * get and return the value of the filter.
124 * Defaults to Ext.emptyFn.
125 * @return {Object} The 'serialized' form of this filter
126 * @methodOf Ext.ux.grid.filter.Filter
128 getValue : Ext.emptyFn,
131 * Template method to be implemented by all subclasses that is to
132 * set the value of the filter and fire the 'update' event.
133 * Defaults to Ext.emptyFn.
134 * @param {Object} data The value to set the filter
135 * @methodOf Ext.ux.grid.filter.Filter
137 setValue : Ext.emptyFn,
140 * Template method to be implemented by all subclasses that is to
141 * return <tt>true</tt> if the filter has enough configuration information to be activated.
142 * Defaults to <tt>return true</tt>.
145 isActivatable : function(){
150 * Template method to be implemented by all subclasses that is to
151 * get and return serialized filter data for transmission to the server.
152 * Defaults to Ext.emptyFn.
154 getSerialArgs : Ext.emptyFn,
157 * Template method to be implemented by all subclasses that is to
158 * validates the provided Ext.data.Record against the filters configuration.
159 * Defaults to <tt>return true</tt>.
160 * @param {Ext.data.Record} record The record to validate
161 * @return {Boolean} true if the record is valid within the bounds
162 * of the filter, false otherwise.
164 validateRecord : function(){
169 * Returns the serialized filter data for transmission to the server
170 * and fires the 'serialize' event.
171 * @return {Object/Array} An object or collection of objects containing
172 * key value pairs representing the current configuration of the filter.
173 * @methodOf Ext.ux.grid.filter.Filter
175 serialize : function(){
176 var args = this.getSerialArgs();
177 this.fireEvent('serialize', args, this);
182 fireUpdate : function(){
184 this.fireEvent('update', this);
186 this.setActive(this.isActivatable());
190 * Sets the status of the filter and fires the appropriate events.
191 * @param {Boolean} active The new filter state.
192 * @param {Boolean} suppressEvent True to prevent events from being fired.
193 * @methodOf Ext.ux.grid.filter.Filter
195 setActive : function(active, suppressEvent){
196 if(this.active != active){
197 this.active = active;
198 if (suppressEvent !== true) {
199 this.fireEvent(active ? 'activate' : 'deactivate', this);