provide installation instructions
[extjs.git] / examples / grid-filtering / grid / filter / StringFilter.js
1 /*\r
2  * Ext JS Library 2.2.1\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 Ext.grid.filter.StringFilter = Ext.extend(Ext.grid.filter.Filter, {\r
10         updateBuffer: 500,\r
11         icon: '/img/small_icons/famfamfam/find.png',\r
12         \r
13         init: function() {\r
14                 var value = this.value = new Ext.menu.EditableItem({icon: this.icon});\r
15                 value.on('keyup', this.onKeyUp, this);\r
16                 this.menu.add(value);\r
17                 \r
18                 this.updateTask = new Ext.util.DelayedTask(this.fireUpdate, this);\r
19         },\r
20         \r
21         onKeyUp: function(event) {\r
22                 if(event.getKey() == event.ENTER){\r
23                         this.menu.hide(true);\r
24                         return;\r
25                 }\r
26                 this.updateTask.delay(this.updateBuffer);\r
27         },\r
28         \r
29         isActivatable: function() {\r
30                 return this.value.getValue().length > 0;\r
31         },\r
32         \r
33         fireUpdate: function() {                \r
34                 if(this.active) {\r
35                         this.fireEvent("update", this);\r
36     }\r
37                 this.setActive(this.isActivatable());\r
38         },\r
39         \r
40         setValue: function(value) {\r
41                 this.value.setValue(value);\r
42                 this.fireEvent("update", this);\r
43         },\r
44         \r
45         getValue: function() {\r
46                 return this.value.getValue();\r
47         },\r
48         \r
49         serialize: function() {\r
50                 var args = {type: 'string', value: this.getValue()};\r
51                 this.fireEvent('serialize', args, this);\r
52                 return args;\r
53         },\r
54         \r
55         validateRecord: function(record) {\r
56                 var val = record.get(this.dataIndex);\r
57                 if(typeof val != "string") {\r
58                         return this.getValue().length == 0;\r
59     }\r
60                 return val.toLowerCase().indexOf(this.getValue().toLowerCase()) > -1;\r
61         }\r
62 });