2 * @class Ext.ux.grid.filter.StringFilter
3 * @extends Ext.ux.grid.filter.Filter
4 * Filter by a configurable Ext.form.field.Text
5 * <p><b><u>Example Usage:</u></b></p>
7 var filters = Ext.create('Ext.ux.grid.GridFilters', {
16 active: true, // default is false
17 iconCls: 'ux-gridfilter-text-icon' // default
18 // any Ext.form.field.Text configs accepted
23 Ext.define('Ext.ux.grid.filter.StringFilter', {
24 extend: 'Ext.ux.grid.filter.Filter',
25 alias: 'gridfilter.string',
28 * @cfg {String} iconCls
29 * The iconCls to be applied to the menu item.
30 * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
32 iconCls : 'ux-gridfilter-text-icon',
34 emptyText: 'Enter Filter Text...',
40 * Template method that is to initialize the filter and install required menu items.
42 init : function (config) {
44 enableKeyEvents: true,
45 iconCls: this.iconCls,
49 keyup: this.onInputKeyUp,
58 this.inputItem = Ext.create('Ext.form.field.Text', config);
59 this.menu.add(this.inputItem);
60 this.updateTask = Ext.create('Ext.util.DelayedTask', this.fireUpdate, this);
65 * Template method that is to get and return the value of the filter.
66 * @return {String} The value of this filter
68 getValue : function () {
69 return this.inputItem.getValue();
74 * Template method that is to set the value of the filter.
75 * @param {Object} value The value to set the filter
77 setValue : function (value) {
78 this.inputItem.setValue(value);
79 this.fireEvent('update', this);
84 * Template method that is to return <tt>true</tt> if the filter
85 * has enough configuration information to be activated.
88 isActivatable : function () {
89 return this.inputItem.getValue().length > 0;
94 * Template method that is to get and return serialized filter data for
95 * transmission to the server.
96 * @return {Object/Array} An object or collection of objects containing
97 * key value pairs representing the current configuration of the filter.
99 getSerialArgs : function () {
100 return {type: 'string', value: this.getValue()};
104 * Template method that is to validate the provided Ext.data.Record
105 * against the filters configuration.
106 * @param {Ext.data.Record} record The record to validate
107 * @return {Boolean} true if the record is valid within the bounds
108 * of the filter, false otherwise.
110 validateRecord : function (record) {
111 var val = record.get(this.dataIndex);
113 if(typeof val != 'string') {
114 return (this.getValue().length === 0);
117 return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
122 * Handler method called when there is a keyup event on this.inputItem
124 onInputKeyUp : function (field, e) {
126 if (k == e.RETURN && field.isValid()) {
132 this.updateTask.delay(this.updateBuffer);