3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
7 Ext.namespace('Ext.ux.grid.filter');
10 * @class Ext.ux.grid.filter.Filter
11 * @extends Ext.util.Observable
12 * Abstract base class for filter implementations.
14 Ext.ux.grid.filter.Filter = Ext.extend(Ext.util.Observable, {
16 * @cfg {Boolean} active
17 * Indicates the initial status of the filter (defaults to false).
21 * True if this filter is active. Use setActive() to alter after configuration.
26 * @cfg {String} dataIndex
27 * The {@link Ext.data.Store} dataIndex of the field this filter represents.
28 * The dataIndex does not actually have to exist in the store.
32 * The filter configuration menu that will be installed into the filter submenu of a column menu.
38 * @cfg {Number} updateBuffer
39 * Number of milliseconds to wait after user interaction to fire an update. Only supported
40 * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
44 constructor : function (config) {
45 Ext.apply(this, config);
50 * Fires when an inactive filter becomes active
51 * @param {Ext.ux.grid.filter.Filter} this
56 * Fires when an active filter becomes inactive
57 * @param {Ext.ux.grid.filter.Filter} this
62 * Fires after the serialization process. Use this to attach additional parameters to serialization
63 * data before it is encoded and sent to the server.
64 * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
65 * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
70 * Fires when a filter configuration has changed
71 * @param {Ext.ux.grid.filter.Filter} this The filter object.
75 Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
77 this.menu = new Ext.menu.Menu();
79 if(config && config.value){
80 this.setValue(config.value);
81 this.setActive(config.active !== false, true);
87 * Destroys this filter by purging any event listeners, and removing any menus.
93 this.purgeListeners();
97 * Template method to be implemented by all subclasses that is to
98 * initialize the filter and install required menu items.
99 * Defaults to Ext.emptyFn.
104 * Template method to be implemented by all subclasses that is to
105 * get and return the value of the filter.
106 * Defaults to Ext.emptyFn.
107 * @return {Object} The 'serialized' form of this filter
108 * @methodOf Ext.ux.grid.filter.Filter
110 getValue : Ext.emptyFn,
113 * Template method to be implemented by all subclasses that is to
114 * set the value of the filter and fire the 'update' event.
115 * Defaults to Ext.emptyFn.
116 * @param {Object} data The value to set the filter
117 * @methodOf Ext.ux.grid.filter.Filter
119 setValue : Ext.emptyFn,
122 * Template method to be implemented by all subclasses that is to
123 * return <tt>true</tt> if the filter has enough configuration information to be activated.
124 * Defaults to <tt>return true</tt>.
127 isActivatable : function(){
132 * Template method to be implemented by all subclasses that is to
133 * get and return serialized filter data for transmission to the server.
134 * Defaults to Ext.emptyFn.
136 getSerialArgs : Ext.emptyFn,
139 * Template method to be implemented by all subclasses that is to
140 * validates the provided Ext.data.Record against the filters configuration.
141 * Defaults to <tt>return true</tt>.
142 * @param {Ext.data.Record} record The record to validate
143 * @return {Boolean} true if the record is valid within the bounds
144 * of the filter, false otherwise.
146 validateRecord : function(){
151 * Returns the serialized filter data for transmission to the server
152 * and fires the 'serialize' event.
153 * @return {Object/Array} An object or collection of objects containing
154 * key value pairs representing the current configuration of the filter.
155 * @methodOf Ext.ux.grid.filter.Filter
157 serialize : function(){
158 var args = this.getSerialArgs();
159 this.fireEvent('serialize', args, this);
164 fireUpdate : function(){
166 this.fireEvent('update', this);
168 this.setActive(this.isActivatable());
172 * Sets the status of the filter and fires the appropriate events.
173 * @param {Boolean} active The new filter state.
174 * @param {Boolean} suppressEvent True to prevent events from being fired.
175 * @methodOf Ext.ux.grid.filter.Filter
177 setActive : function(active, suppressEvent){
178 if(this.active != active){
179 this.active = active;
180 if (suppressEvent !== true) {
181 this.fireEvent(active ? 'activate' : 'deactivate', this);