1
<html><head><title>TableLayout.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>TableLayout.js</h1><pre class="highlighted"><code><i>/**
2
* @class Ext.layout.TableLayout
3
* @extends Ext.layout.ContainerLayout
4
* <p>This layout allows you to easily render content into an HTML table. The total number of columns can be
5
* specified, and rowspan and colspan can be used to create complex layouts within the table.
6
* This class is intended to be extended or created via the layout:<em>'table'</em> {@link Ext.Container#layout} config,
7
* and should generally not need to be created directly via the <b>new</b> keyword.</p>
8
* <p>Note that when creating a layout via config, the layout-specific config properties must be passed <b>in</b> via
9
* the {@link Ext.Container#layoutConfig} object which will then be applied internally to the layout. In the
10
* <b>case</b> of TableLayout, the only valid layout config property is {@link #columns}. However, the items added to a
11
* TableLayout can supply the following table-specific config properties:</p>
13
* <li><b>rowspan</b> Applied to the table cell containing the item.</li>
14
* <li><b>colspan</b> Applied to the table cell containing the item.</li>
15
* <li><b>cellId</b> An id applied to the table cell containing the item.</li>
16
* <li><b>cellCls</b> A CSS class name added to the table cell containing the item.</li>
18
* <p>The basic concept of building up a TableLayout is conceptually very similar to building up a standard
19
* HTML table. You simply add each panel (or "cell") that you want to include along <b>with</b> any span attributes
20
* specified as the special config properties of rowspan and colspan which work exactly like their HTML counterparts.
21
* Rather than explicitly creating and nesting rows and columns as you would <b>in</b> HTML, you simply specify the
22
* total column count <b>in</b> the layoutConfig and start adding panels <b>in</b> their natural order from left to right,
23
* top to bottom. The layout will automatically figure out, based on the column count, rowspans and colspans,
24
* how to position each panel within the table. Just like <b>with</b> HTML tables, your rowspans and colspans must add
25
* up correctly <b>in</b> your overall layout or you'll end up <b>with</b> missing and/or extra cells! Example usage:</p>
26
* <pre><code>
27
<i>// This code will generate a layout table that is 3 columns by 2 rows</i>
28
<i>// <b>with</b> some spanning included. The basic layout will be:</i>
29
<i>// +--------+-----------------+</i>
31
<i>// | |--------+--------|</i>
33
<i>// +--------+--------+--------+</i>
34
<b>var</b> table = <b>new</b> Ext.Panel({
35
title: <em>'Table Layout'</em>,
36
layout:<em>'table'</em>,
38
<i>// applied to each contained panel</i>
39
bodyStyle:<em>'padding:20px'</em>
42
<i>// The total column count must be specified here</i>
46
html: <em>'&lt;p&gt;Cell A content&lt;/p&gt;'</em>,
49
html: <em>'&lt;p&gt;Cell B content&lt;/p&gt;'</em>,
52
html: <em>'&lt;p&gt;Cell C content&lt;/p&gt;'</em>,
53
cellCls: <em>'highlight'</em>
55
html: <em>'&lt;p&gt;Cell D content&lt;/p&gt;'</em>
58
</code></pre>
60
Ext.layout.TableLayout = Ext.extend(Ext.layout.ContainerLayout, {
62
* @cfg {Number} columns
63
* The total number of columns to create <b>in</b> the table <b>for</b> this layout. If not specified, all panels added to
64
* <b>this</b> layout will be rendered into a single row using a column per panel.
71
setContainer : <b>function</b>(ct){
72
Ext.layout.TableLayout.superclass.setContainer.call(<b>this</b>, ct);
74
<b>this</b>.currentRow = 0;
75
<b>this</b>.currentColumn = 0;
76
<b>this</b>.cells = [];
80
onLayout : <b>function</b>(ct, target){
81
<b>var</b> cs = ct.items.items, len = cs.length, c, i;
83
<b>if</b>(!<b>this</b>.table){
84
target.addClass(<em>'x-table-layout-ct'</em>);
86
<b>this</b>.table = target.createChild(
87
{tag:<em>'table'</em>, cls:<em>'x-table-layout'</em>, cellspacing: 0, cn: {tag: <em>'tbody'</em>}}, null, true);
89
<b>this</b>.renderAll(ct, target);
93
getRow : <b>function</b>(index){
94
<b>var</b> row = <b>this</b>.table.tBodies[0].childNodes[index];
96
row = document.createElement(<em>'tr'</em>);
97
<b>this</b>.table.tBodies[0].appendChild(row);
103
getNextCell : <b>function</b>(c){
104
<b>var</b> cell = <b>this</b>.getNextNonSpan(<b>this</b>.currentColumn, <b>this</b>.currentRow);
105
<b>var</b> curCol = <b>this</b>.currentColumn = cell[0], curRow = <b>this</b>.currentRow = cell[1];
106
<b>for</b>(var rowIndex = curRow; rowIndex < curRow + (c.rowspan || 1); rowIndex++){
107
<b>if</b>(!<b>this</b>.cells[rowIndex]){
108
<b>this</b>.cells[rowIndex] = [];
110
<b>for</b>(var colIndex = curCol; colIndex < curCol + (c.colspan || 1); colIndex++){
111
<b>this</b>.cells[rowIndex][colIndex] = true;
114
<b>var</b> td = document.createElement(<em>'td'</em>);
118
<b>var</b> cls = <em>'x-table-layout-cell'</em>;
119
<b>if</b>(c.cellCls){
120
cls += <em>' '</em> + c.cellCls;
123
<b>if</b>(c.colspan){
124
td.colSpan = c.colspan;
126
<b>if</b>(c.rowspan){
127
td.rowSpan = c.rowspan;
129
<b>this</b>.getRow(curRow).appendChild(td);
134
getNextNonSpan: <b>function</b>(colIndex, rowIndex){
135
<b>var</b> cols = <b>this</b>.columns;
136
<b>while</b>((cols && colIndex >= cols) || (<b>this</b>.cells[rowIndex] && <b>this</b>.cells[rowIndex][colIndex])) {
137
<b>if</b>(cols && colIndex >= cols){
144
<b>return</b> [colIndex, rowIndex];
148
renderItem : <b>function</b>(c, position, target){
149
<b>if</b>(c && !c.rendered){
150
c.render(<b>this</b>.getNextCell(c));
151
<b>if</b>(this.extraCls){
152
<b>var</b> t = c.getPositionEl ? c.getPositionEl() : c;
153
t.addClass(<b>this</b>.extraCls);
159
isValidParent : <b>function</b>(c, target){
164
* @property activeItem
169
Ext.Container.LAYOUTS[<em>'table'</em>] = Ext.layout.TableLayout;</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
b'\\ No newline at end of file'