3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.layout.TableLayout"></div>/**
\r
10 * @class Ext.layout.TableLayout
\r
11 * @extends Ext.layout.ContainerLayout
\r
12 * <p>This layout allows you to easily render content into an HTML table. The total number of columns can be
\r
13 * specified, and rowspan and colspan can be used to create complex layouts within the table.
\r
14 * This class is intended to be extended or created via the layout:'table' {@link Ext.Container#layout} config,
\r
15 * and should generally not need to be created directly via the new keyword.</p>
\r
16 * <p>Note that when creating a layout via config, the layout-specific config properties must be passed in via
\r
17 * the {@link Ext.Container#layoutConfig} object which will then be applied internally to the layout. In the
\r
18 * case of TableLayout, the only valid layout config property is {@link #columns}. However, the items added to a
\r
19 * TableLayout can supply the following table-specific config properties:</p>
\r
21 * <li><b>rowspan</b> Applied to the table cell containing the item.</li>
\r
22 * <li><b>colspan</b> Applied to the table cell containing the item.</li>
\r
23 * <li><b>cellId</b> An id applied to the table cell containing the item.</li>
\r
24 * <li><b>cellCls</b> A CSS class name added to the table cell containing the item.</li>
\r
26 * <p>The basic concept of building up a TableLayout is conceptually very similar to building up a standard
\r
27 * HTML table. You simply add each panel (or "cell") that you want to include along with any span attributes
\r
28 * specified as the special config properties of rowspan and colspan which work exactly like their HTML counterparts.
\r
29 * Rather than explicitly creating and nesting rows and columns as you would in HTML, you simply specify the
\r
30 * total column count in the layoutConfig and start adding panels in their natural order from left to right,
\r
31 * top to bottom. The layout will automatically figure out, based on the column count, rowspans and colspans,
\r
32 * how to position each panel within the table. Just like with HTML tables, your rowspans and colspans must add
\r
33 * up correctly in your overall layout or you'll end up with missing and/or extra cells! Example usage:</p>
\r
35 // This code will generate a layout table that is 3 columns by 2 rows
\r
36 // with some spanning included. The basic layout will be:
\r
37 // +--------+-----------------+
\r
39 // | |--------+--------|
\r
41 // +--------+--------+--------+
\r
42 var table = new Ext.Panel({
\r
43 title: 'Table Layout',
\r
46 // applied to each contained panel
\r
47 bodyStyle:'padding:20px'
\r
50 // The total column count must be specified here
\r
54 html: '<p>Cell A content</p>',
\r
57 html: '<p>Cell B content</p>',
\r
60 html: '<p>Cell C content</p>',
\r
61 cellCls: 'highlight'
\r
63 html: '<p>Cell D content</p>'
\r
68 Ext.layout.TableLayout = Ext.extend(Ext.layout.ContainerLayout, {
\r
69 <div id="cfg-Ext.layout.TableLayout-columns"></div>/**
\r
70 * @cfg {Number} columns
\r
71 * The total number of columns to create in the table for this layout. If not specified, all Components added to
\r
72 * this layout will be rendered into a single row using one column per Component.
\r
76 monitorResize:false,
\r
80 targetCls: 'x-table-layout-ct',
\r
82 <div id="cfg-Ext.layout.TableLayout-tableAttrs"></div>/**
\r
83 * @cfg {Object} tableAttrs
\r
84 * <p>An object containing properties which are added to the {@link Ext.DomHelper DomHelper} specification
\r
85 * used to create the layout's <tt><table></tt> element. Example:</p><pre><code>
\r
102 setContainer : function(ct){
\r
103 Ext.layout.TableLayout.superclass.setContainer.call(this, ct);
\r
105 this.currentRow = 0;
\r
106 this.currentColumn = 0;
\r
111 onLayout : function(ct, target){
\r
112 var cs = ct.items.items, len = cs.length, c, i;
\r
115 target.addClass('x-table-layout-ct');
\r
117 this.table = target.createChild(
\r
118 Ext.apply({tag:'table', cls:'x-table-layout', cellspacing: 0, cn: {tag: 'tbody'}}, this.tableAttrs), null, true);
\r
120 this.renderAll(ct, target);
\r
124 getRow : function(index){
\r
125 var row = this.table.tBodies[0].childNodes[index];
\r
127 row = document.createElement('tr');
\r
128 this.table.tBodies[0].appendChild(row);
\r
134 getNextCell : function(c){
\r
135 var cell = this.getNextNonSpan(this.currentColumn, this.currentRow);
\r
136 var curCol = this.currentColumn = cell[0], curRow = this.currentRow = cell[1];
\r
137 for(var rowIndex = curRow; rowIndex < curRow + (c.rowspan || 1); rowIndex++){
\r
138 if(!this.cells[rowIndex]){
\r
139 this.cells[rowIndex] = [];
\r
141 for(var colIndex = curCol; colIndex < curCol + (c.colspan || 1); colIndex++){
\r
142 this.cells[rowIndex][colIndex] = true;
\r
145 var td = document.createElement('td');
\r
149 var cls = 'x-table-layout-cell';
\r
151 cls += ' ' + c.cellCls;
\r
153 td.className = cls;
\r
155 td.colSpan = c.colspan;
\r
158 td.rowSpan = c.rowspan;
\r
160 this.getRow(curRow).appendChild(td);
\r
165 getNextNonSpan: function(colIndex, rowIndex){
\r
166 var cols = this.columns;
\r
167 while((cols && colIndex >= cols) || (this.cells[rowIndex] && this.cells[rowIndex][colIndex])) {
\r
168 if(cols && colIndex >= cols){
\r
175 return [colIndex, rowIndex];
\r
179 renderItem : function(c, position, target){
\r
180 // Ensure we have our inner table to get cells to render into.
\r
182 this.table = target.createChild(
\r
183 Ext.apply({tag:'table', cls:'x-table-layout', cellspacing: 0, cn: {tag: 'tbody'}}, this.tableAttrs), null, true);
\r
185 if(c && !c.rendered){
\r
186 c.render(this.getNextCell(c));
\r
187 this.configureItem(c, position);
\r
188 }else if(c && !this.isValidParent(c, target)){
\r
189 var container = this.getNextCell(c);
\r
190 container.insertBefore(c.getPositionEl().dom, null);
\r
191 c.container = Ext.get(container);
\r
192 this.configureItem(c, position);
\r
197 isValidParent : function(c, target){
\r
198 return c.getPositionEl().up('table', 5).dom.parentNode === (target.dom || target);
\r
201 <div id="prop-Ext.layout.TableLayout-activeItem"></div>/**
\r
202 * @property activeItem
\r
207 Ext.Container.LAYOUTS['table'] = Ext.layout.TableLayout;</pre>
\r