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