Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / docs / source / TableChunker.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="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../resources/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-view-TableChunker'>/**
19 </span> * @class Ext.view.TableChunker
20  * 
21  * Produces optimized XTemplates for chunks of tables to be
22  * used in grids, trees and other table based widgets.
23  *
24  * @singleton
25  */
26 Ext.define('Ext.view.TableChunker', {
27     singleton: true,
28     requires: ['Ext.XTemplate'],
29     metaTableTpl: [
30         '{[this.openTableWrap()]}',
31         '&lt;table class=&quot;' + Ext.baseCSSPrefix + 'grid-table ' + Ext.baseCSSPrefix + 'grid-table-resizer&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; {[this.embedFullWidth()]}&gt;',
32             '&lt;tbody&gt;',
33             '&lt;tr class=&quot;' + Ext.baseCSSPrefix + 'grid-header-row&quot;&gt;',
34             '&lt;tpl for=&quot;columns&quot;&gt;',
35                 '&lt;th class=&quot;' + Ext.baseCSSPrefix + 'grid-col-resizer-{id}&quot; style=&quot;width: {width}px; height: 0px;&quot;&gt;&lt;/th&gt;',
36             '&lt;/tpl&gt;',
37             '&lt;/tr&gt;',
38             '{[this.openRows()]}',
39                 '{row}',
40                 '&lt;tpl for=&quot;features&quot;&gt;',
41                     '{[this.embedFeature(values, parent, xindex, xcount)]}',
42                 '&lt;/tpl&gt;',
43             '{[this.closeRows()]}',
44             '&lt;/tbody&gt;',
45         '&lt;/table&gt;',
46         '{[this.closeTableWrap()]}'
47     ],
48
49     constructor: function() {
50         Ext.XTemplate.prototype.recurse = function(values, reference) {
51             return this.apply(reference ? values[reference] : values);
52         };
53     },
54
55     embedFeature: function(values, parent, x, xcount) {
56         var tpl = '';
57         if (!values.disabled) {
58             tpl = values.getFeatureTpl(values, parent, x, xcount);
59         }
60         return tpl;
61     },
62
63     embedFullWidth: function() {
64         return 'style=&quot;width: {fullWidth}px;&quot;';
65     },
66
67     openRows: function() {
68         return '&lt;tpl for=&quot;rows&quot;&gt;';
69     },
70
71     closeRows: function() {
72         return '&lt;/tpl&gt;';
73     },
74
75     metaRowTpl: [
76         '&lt;tr class=&quot;' + Ext.baseCSSPrefix + 'grid-row {addlSelector} {[this.embedRowCls()]}&quot; {[this.embedRowAttr()]}&gt;',
77             '&lt;tpl for=&quot;columns&quot;&gt;',
78                 '&lt;td class=&quot;{cls} ' + Ext.baseCSSPrefix + 'grid-cell ' + Ext.baseCSSPrefix + 'grid-cell-{columnId} {{id}-modified} {{id}-tdCls} {[this.firstOrLastCls(xindex, xcount)]}&quot; {{id}-tdAttr}&gt;&lt;div unselectable=&quot;on&quot; class=&quot;' + Ext.baseCSSPrefix + 'grid-cell-inner ' + Ext.baseCSSPrefix + 'unselectable&quot; style=&quot;{{id}-style}; text-align: {align};&quot;&gt;{{id}}&lt;/div&gt;&lt;/td&gt;',
79             '&lt;/tpl&gt;',
80         '&lt;/tr&gt;'
81     ],
82     
83     firstOrLastCls: function(xindex, xcount) {
84         var cssCls = '';
85         if (xindex === 1) {
86             cssCls = Ext.baseCSSPrefix + 'grid-cell-first';
87         } else if (xindex === xcount) {
88             cssCls = Ext.baseCSSPrefix + 'grid-cell-last';
89         }
90         return cssCls;
91     },
92     
93     embedRowCls: function() {
94         return '{rowCls}';
95     },
96     
97     embedRowAttr: function() {
98         return '{rowAttr}';
99     },
100     
101     openTableWrap: function() {
102         return '';
103     },
104     
105     closeTableWrap: function() {
106         return '';
107     },
108
109     getTableTpl: function(cfg, textOnly) {
110         var tpl,
111             tableTplMemberFns = {
112                 openRows: this.openRows,
113                 closeRows: this.closeRows,
114                 embedFeature: this.embedFeature,
115                 embedFullWidth: this.embedFullWidth,
116                 openTableWrap: this.openTableWrap,
117                 closeTableWrap: this.closeTableWrap
118             },
119             tplMemberFns = {},
120             features = cfg.features || [],
121             ln = features.length,
122             i  = 0,
123             memberFns = {
124                 embedRowCls: this.embedRowCls,
125                 embedRowAttr: this.embedRowAttr,
126                 firstOrLastCls: this.firstOrLastCls
127             },
128             // copy the default
129             metaRowTpl = Array.prototype.slice.call(this.metaRowTpl, 0),
130             metaTableTpl;
131             
132         for (; i &lt; ln; i++) {
133             if (!features[i].disabled) {
134                 features[i].mutateMetaRowTpl(metaRowTpl);
135                 Ext.apply(memberFns, features[i].getMetaRowTplFragments());
136                 Ext.apply(tplMemberFns, features[i].getFragmentTpl());
137                 Ext.apply(tableTplMemberFns, features[i].getTableFragments());
138             }
139         }
140         
141         metaRowTpl = Ext.create('Ext.XTemplate', metaRowTpl.join(''), memberFns);
142         cfg.row = metaRowTpl.applyTemplate(cfg);
143         
144         metaTableTpl = Ext.create('Ext.XTemplate', this.metaTableTpl.join(''), tableTplMemberFns);
145         
146         tpl = metaTableTpl.applyTemplate(cfg);
147         
148         // TODO: Investigate eliminating.
149         if (!textOnly) {
150             tpl = Ext.create('Ext.XTemplate', tpl, tplMemberFns);
151         }
152         return tpl;
153         
154     }
155 });
156 </pre>
157 </body>
158 </html>