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.StringFilter
17 * @extends Ext.ux.grid.filter.Filter
18 * Filter by a configurable Ext.form.field.Text
19 * <p><b><u>Example Usage:</u></b></p>
21 var filters = Ext.create('Ext.ux.grid.GridFilters', {
30 active: true, // default is false
31 iconCls: 'ux-gridfilter-text-icon' // default
32 // any Ext.form.field.Text configs accepted
37 Ext.define('Ext.ux.grid.filter.StringFilter', {
38 extend: 'Ext.ux.grid.filter.Filter',
39 alias: 'gridfilter.string',
42 * @cfg {String} iconCls
43 * The iconCls to be applied to the menu item.
44 * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
46 iconCls : 'ux-gridfilter-text-icon',
48 emptyText: 'Enter Filter Text...',
54 * Template method that is to initialize the filter and install required menu items.
56 init : function (config) {
58 enableKeyEvents: true,
59 iconCls: this.iconCls,
63 keyup: this.onInputKeyUp,
72 this.inputItem = Ext.create('Ext.form.field.Text', config);
73 this.menu.add(this.inputItem);
74 this.updateTask = Ext.create('Ext.util.DelayedTask', this.fireUpdate, this);
79 * Template method that is to get and return the value of the filter.
80 * @return {String} The value of this filter
82 getValue : function () {
83 return this.inputItem.getValue();
88 * Template method that is to set the value of the filter.
89 * @param {Object} value The value to set the filter
91 setValue : function (value) {
92 this.inputItem.setValue(value);
93 this.fireEvent('update', this);
98 * Template method that is to return <tt>true</tt> if the filter
99 * has enough configuration information to be activated.
102 isActivatable : function () {
103 return this.inputItem.getValue().length > 0;
108 * Template method that is to get and return serialized filter data for
109 * transmission to the server.
110 * @return {Object/Array} An object or collection of objects containing
111 * key value pairs representing the current configuration of the filter.
113 getSerialArgs : function () {
114 return {type: 'string', value: this.getValue()};
118 * Template method that is to validate the provided Ext.data.Record
119 * against the filters configuration.
120 * @param {Ext.data.Record} record The record to validate
121 * @return {Boolean} true if the record is valid within the bounds
122 * of the filter, false otherwise.
124 validateRecord : function (record) {
125 var val = record.get(this.dataIndex);
127 if(typeof val != 'string') {
128 return (this.getValue().length === 0);
131 return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
136 * Handler method called when there is a keyup event on this.inputItem
138 onInputKeyUp : function (field, e) {
140 if (k == e.RETURN && field.isValid()) {
146 this.updateTask.delay(this.updateBuffer);