2 * @class Ext.ux.grid.filter.Filter
3 * @extends Ext.util.Observable
4 * Abstract base class for filter implementations.
6 Ext.define('Ext.ux.grid.filter.Filter', {
7 extend: 'Ext.util.Observable',
10 * @cfg {Boolean} active
11 * Indicates the initial status of the filter (defaults to false).
15 * True if this filter is active. Use setActive() to alter after configuration.
20 * @cfg {String} dataIndex
21 * The {@link Ext.data.Store} dataIndex of the field this filter represents.
22 * The dataIndex does not actually have to exist in the store.
26 * The filter configuration menu that will be installed into the filter submenu of a column menu.
32 * @cfg {Number} updateBuffer
33 * Number of milliseconds to wait after user interaction to fire an update. Only supported
34 * by filters: 'list', 'numeric', and 'string'. Defaults to 500.
38 constructor : function (config) {
39 Ext.apply(this, config);
44 * Fires when an inactive filter becomes active
45 * @param {Ext.ux.grid.filter.Filter} this
50 * Fires when an active filter becomes inactive
51 * @param {Ext.ux.grid.filter.Filter} this
56 * Fires after the serialization process. Use this to attach additional parameters to serialization
57 * data before it is encoded and sent to the server.
58 * @param {Array/Object} data A map or collection of maps representing the current filter configuration.
59 * @param {Ext.ux.grid.filter.Filter} filter The filter being serialized.
64 * Fires when a filter configuration has changed
65 * @param {Ext.ux.grid.filter.Filter} this The filter object.
69 Ext.ux.grid.filter.Filter.superclass.constructor.call(this);
71 this.menu = this.createMenu(config);
73 if(config && config.value){
74 this.setValue(config.value);
75 this.setActive(config.active !== false, true);
81 * Destroys this filter by purging any event listeners, and removing any menus.
87 this.clearListeners();
91 * Template method to be implemented by all subclasses that is to
92 * initialize the filter and install required menu items.
93 * Defaults to Ext.emptyFn.
99 * Creates the Menu for this filter.
100 * @param {Object} config Filter configuration
101 * @return {Ext.menu.Menu}
103 createMenu: function(config) {
104 return Ext.create('Ext.menu.Menu', config);
108 * Template method to be implemented by all subclasses that is to
109 * get and return the value of the filter.
110 * Defaults to Ext.emptyFn.
111 * @return {Object} The 'serialized' form of this filter
112 * @methodOf Ext.ux.grid.filter.Filter
114 getValue : Ext.emptyFn,
117 * Template method to be implemented by all subclasses that is to
118 * set the value of the filter and fire the 'update' event.
119 * Defaults to Ext.emptyFn.
120 * @param {Object} data The value to set the filter
121 * @methodOf Ext.ux.grid.filter.Filter
123 setValue : Ext.emptyFn,
126 * Template method to be implemented by all subclasses that is to
127 * return <tt>true</tt> if the filter has enough configuration information to be activated.
128 * Defaults to <tt>return true</tt>.
131 isActivatable : function(){
136 * Template method to be implemented by all subclasses that is to
137 * get and return serialized filter data for transmission to the server.
138 * Defaults to Ext.emptyFn.
140 getSerialArgs : Ext.emptyFn,
143 * Template method to be implemented by all subclasses that is to
144 * validates the provided Ext.data.Record against the filters configuration.
145 * Defaults to <tt>return true</tt>.
146 * @param {Ext.data.Record} record The record to validate
147 * @return {Boolean} true if the record is valid within the bounds
148 * of the filter, false otherwise.
150 validateRecord : function(){
155 * Returns the serialized filter data for transmission to the server
156 * and fires the 'serialize' event.
157 * @return {Object/Array} An object or collection of objects containing
158 * key value pairs representing the current configuration of the filter.
159 * @methodOf Ext.ux.grid.filter.Filter
161 serialize : function(){
162 var args = this.getSerialArgs();
163 this.fireEvent('serialize', args, this);
168 fireUpdate : function(){
170 this.fireEvent('update', this);
172 this.setActive(this.isActivatable());
176 * Sets the status of the filter and fires the appropriate events.
177 * @param {Boolean} active The new filter state.
178 * @param {Boolean} suppressEvent True to prevent events from being fired.
179 * @methodOf Ext.ux.grid.filter.Filter
181 setActive : function(active, suppressEvent){
182 if(this.active != active){
183 this.active = active;
184 if (suppressEvent !== true) {
185 this.fireEvent(active ? 'activate' : 'deactivate', this);