Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / Column3.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-tree-Column'>/**
19 </span> * @class Ext.tree.Column
20  * @extends Ext.grid.column.Column
21  * 
22  * Provides indentation and folder structure markup for a Tree taking into account
23  * depth and position within the tree hierarchy.
24  * 
25  * @private
26  */
27 Ext.define('Ext.tree.Column', {
28     extend: 'Ext.grid.column.Column',
29     alias: 'widget.treecolumn',
30
31     initComponent: function() {
32         var origRenderer = this.renderer || this.defaultRenderer,
33             origScope    = this.scope || window;
34
35         this.renderer = function(value, metaData, record, rowIdx, colIdx, store, view) {
36             var buf   = [],
37                 format = Ext.String.format,
38                 depth = record.getDepth(),
39                 treePrefix  = Ext.baseCSSPrefix + 'tree-',
40                 elbowPrefix = treePrefix + 'elbow-',
41                 expanderCls = treePrefix + 'expander',
42                 imgText     = '&lt;img src=&quot;{1}&quot; class=&quot;{0}&quot; /&gt;',
43                 checkboxText= '&lt;input type=&quot;button&quot; role=&quot;checkbox&quot; class=&quot;{0}&quot; {1} /&gt;',
44                 formattedValue = origRenderer.apply(origScope, arguments),
45                 href = record.get('href'),
46                 target = record.get('hrefTarget'),
47                 cls = record.get('cls');
48
49             while (record) {
50                 if (!record.isRoot() || (record.isRoot() &amp;&amp; view.rootVisible)) {
51                     if (record.getDepth() === depth) {
52                         buf.unshift(format(imgText,
53                             treePrefix + 'icon ' + 
54                             treePrefix + 'icon' + (record.get('icon') ? '-inline ' : (record.isLeaf() ? '-leaf ' : '-parent ')) +
55                             (record.get('iconCls') || ''),
56                             record.get('icon') || Ext.BLANK_IMAGE_URL
57                         ));
58                         if (record.get('checked') !== null) {
59                             buf.unshift(format(
60                                 checkboxText,
61                                 (treePrefix + 'checkbox') + (record.get('checked') ? ' ' + treePrefix + 'checkbox-checked' : ''),
62                                 record.get('checked') ? 'aria-checked=&quot;true&quot;' : ''
63                             ));
64                             if (record.get('checked')) {
65                                 metaData.tdCls += (' ' + Ext.baseCSSPrefix + 'tree-checked');
66                             }
67                         }
68                         if (record.isLast()) {
69                             if (record.isExpandable()) {
70                                 buf.unshift(format(imgText, (elbowPrefix + 'end-plus ' + expanderCls), Ext.BLANK_IMAGE_URL));
71                             } else {
72                                 buf.unshift(format(imgText, (elbowPrefix + 'end'), Ext.BLANK_IMAGE_URL));
73                             }
74                             
75                         } else {
76                             if (record.isExpandable()) {
77                                 buf.unshift(format(imgText, (elbowPrefix + 'plus ' + expanderCls), Ext.BLANK_IMAGE_URL));
78                             } else {
79                                 buf.unshift(format(imgText, (treePrefix + 'elbow'), Ext.BLANK_IMAGE_URL));
80                             }
81                         }
82                     } else {
83                         if (record.isLast() || record.getDepth() === 0) {
84                             buf.unshift(format(imgText, (elbowPrefix + 'empty'), Ext.BLANK_IMAGE_URL));
85                         } else if (record.getDepth() !== 0) {
86                             buf.unshift(format(imgText, (elbowPrefix + 'line'), Ext.BLANK_IMAGE_URL));
87                         }                      
88                     }
89                 }
90                 record = record.parentNode;
91             }
92             if (href) {
93                 formattedValue = format('&lt;a href=&quot;{0}&quot; target=&quot;{1}&quot;&gt;{2}&lt;/a&gt;', href, target, formattedValue);
94             }
95             if (cls) {
96                 metaData.tdCls += ' ' + cls;
97             }
98             return buf.join(&quot;&quot;) + formattedValue;
99         };
100         this.callParent(arguments);
101     },
102
103     defaultRenderer: function(value) {
104         return value;
105     }
106 });</pre>
107 </body>
108 </html>