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