3 <title>The source code</title>
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 <body onload="prettyPrint();">
8 <pre class="prettyprint lang-js"><div id="cls-Ext.ux.grid.filter.StringFilter"></div>/**
\r
9 * @class Ext.ux.grid.filter.StringFilter
\r
10 * @extends Ext.ux.grid.filter.Filter
\r
11 * Filter by a configurable Ext.form.TextField
\r
12 * <p><b><u>Example Usage:</u></b></p>
\r
14 var filters = new Ext.ux.grid.GridFilters({
\r
23 active: true, // default is false
\r
24 iconCls: 'ux-gridfilter-text-icon' // default
\r
25 // any Ext.form.TextField configs accepted
\r
30 Ext.ux.grid.filter.StringFilter = Ext.extend(Ext.ux.grid.filter.Filter, {
\r
32 <div id="cfg-Ext.ux.grid.filter.StringFilter-iconCls"></div>/**
\r
33 * @cfg {String} iconCls
\r
34 * The iconCls to be applied to the menu item.
\r
35 * Defaults to <tt>'ux-gridfilter-text-icon'</tt>.
\r
37 iconCls : 'ux-gridfilter-text-icon',
\r
39 emptyText: 'Enter Filter Text...',
\r
40 selectOnFocus: true,
\r
45 * Template method that is to initialize the filter and install required menu items.
\r
47 init : function (config) {
\r
48 Ext.applyIf(config, {
\r
49 enableKeyEvents: true,
\r
50 iconCls: this.iconCls,
\r
53 keyup: this.onInputKeyUp
\r
57 this.inputItem = new Ext.form.TextField(config);
\r
58 this.menu.add(this.inputItem);
\r
59 this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);
\r
64 * Template method that is to get and return the value of the filter.
\r
65 * @return {String} The value of this filter
\r
67 getValue : function () {
\r
68 return this.inputItem.getValue();
\r
73 * Template method that is to set the value of the filter.
\r
74 * @param {Object} value The value to set the filter
\r
76 setValue : function (value) {
\r
77 this.inputItem.setValue(value);
\r
78 this.fireEvent('update', this);
\r
83 * Template method that is to return <tt>true</tt> if the filter
\r
84 * has enough configuration information to be activated.
\r
87 isActivatable : function () {
\r
88 return this.inputItem.getValue().length > 0;
\r
93 * Template method that is to get and return serialized filter data for
\r
94 * transmission to the server.
\r
95 * @return {Object/Array} An object or collection of objects containing
\r
96 * key value pairs representing the current configuration of the filter.
\r
98 getSerialArgs : function () {
\r
99 return {type: 'string', value: this.getValue()};
\r
102 <div id="method-Ext.ux.grid.filter.StringFilter-validateRecord"></div>/**
\r
103 * Template method that is to validate the provided Ext.data.Record
\r
104 * against the filters configuration.
\r
105 * @param {Ext.data.Record} record The record to validate
\r
106 * @return {Boolean} true if the record is valid within the bounds
\r
107 * of the filter, false otherwise.
\r
109 validateRecord : function (record) {
\r
110 var val = record.get(this.dataIndex);
\r
112 if(typeof val != 'string') {
\r
113 return (this.getValue().length === 0);
\r
116 return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;
\r
121 * Handler method called when there is a keyup event on this.inputItem
\r
123 onInputKeyUp : function (field, e) {
\r
124 var k = e.getKey();
\r
125 if (k == e.RETURN && field.isValid()) {
\r
127 this.menu.hide(true);
\r
130 // restart the timer
\r
131 this.updateTask.delay(this.updateBuffer);
\r