Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / ListSelector.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">// Implementation class for created the tree powered form field\r
9 ListSelector = Ext.extend(Ext.ux.TreeSelector, {\r
10         maxHeight:200,\r
11         listenForLoad: false,\r
12     initComponent : function(){\r
13                 \r
14                 this.tree = new Ext.tree.TreePanel({\r
15                         animate:false,\r
16                         border:false,\r
17                         width: this.treeWidth || 180,\r
18                         autoScroll:true,\r
19                         useArrows:true,\r
20                         selModel: new Ext.tree.ActivationModel(),\r
21                         loader : new ListLoader({store: this.store})            \r
22                 });\r
23                 \r
24                 var root = new Ext.tree.AsyncTreeNode({\r
25                 text: 'All Lists',\r
26                         id: 'root',\r
27                         leaf: false,\r
28                         iconCls: 'icon-folder',\r
29                         expanded: true,\r
30                         isFolder: true\r
31             });\r
32             this.tree.setRootNode(root);\r
33 \r
34         this.tree.on('render', function(){\r
35             this.store.bindTree(this.tree);\r
36         }, this);\r
37                 \r
38         ListSelector.superclass.initComponent.call(this);\r
39                 \r
40                 // selecting folders is not allowed, so filter them\r
41                 this.tree.getSelectionModel().on('beforeselect', this.beforeSelection, this);\r
42                 \r
43                 // if being rendered before the store is loaded, reload when it is loaded\r
44                 if(this.listenForLoad) {\r
45                         this.store.on('load', function(){\r
46                                 root.reload();\r
47                         }, this, {\r
48                                 single: true\r
49                         });\r
50                 }\r
51     },\r
52         \r
53         beforeSelection : function(tree, node){\r
54                 if(node && node.attributes.isFolder){\r
55                         node.toggle();\r
56                         return false;\r
57                 }\r
58         }\r
59 });</pre>    \r
60 </body>\r
61 </html>