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; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-layout-container-Table'>/**
19 </span> * @class Ext.layout.container.Table
20 * @extends Ext.layout.container.Auto
21 * <p>This layout allows you to easily render content into an HTML table. The total number of columns can be
22 * specified, and rowspan and colspan can be used to create complex layouts within the table.
23 * This class is intended to be extended or created via the <code>layout: {type: 'table'}</code>
24 * {@link Ext.container.Container#layout} config, and should generally not need to be created directly via the new keyword.</p>
25 * <p>Note that when creating a layout via config, the layout-specific config properties must be passed in via
26 * the {@link Ext.container.Container#layout} object which will then be applied internally to the layout. In the
27 * case of TableLayout, the only valid layout config properties are {@link #columns} and {@link #tableAttrs}.
28 * However, the items added to a TableLayout can supply the following table-specific config properties:</p>
30 * <li><b>rowspan</b> Applied to the table cell containing the item.</li>
31 * <li><b>colspan</b> Applied to the table cell containing the item.</li>
32 * <li><b>cellId</b> An id applied to the table cell containing the item.</li>
33 * <li><b>cellCls</b> A CSS class name added to the table cell containing the item.</li>
35 * <p>The basic concept of building up a TableLayout is conceptually very similar to building up a standard
36 * HTML table. You simply add each panel (or "cell") that you want to include along with any span attributes
37 * specified as the special config properties of rowspan and colspan which work exactly like their HTML counterparts.
38 * Rather than explicitly creating and nesting rows and columns as you would in HTML, you simply specify the
39 * total column count in the layoutConfig and start adding panels in their natural order from left to right,
40 * top to bottom. The layout will automatically figure out, based on the column count, rowspans and colspans,
41 * how to position each panel within the table. Just like with HTML tables, your rowspans and colspans must add
42 * up correctly in your overall layout or you'll end up with missing and/or extra cells! Example usage:</p>
43 * {@img Ext.layout.container.Table/Ext.layout.container.Table.png Ext.layout.container.Table container layout}
44 * <pre><code>
45 // This code will generate a layout table that is 3 columns by 2 rows
46 // with some spanning included. The basic layout will be:
47 // +--------+-----------------+
49 // | |--------+--------|
51 // +--------+--------+--------+
52 Ext.create('Ext.panel.Panel', {
53 title: 'Table Layout',
58 // The total column count must be specified here
62 // applied to each contained panel
63 bodyStyle:'padding:20px'
66 html: 'Cell A content',
69 html: 'Cell B content',
72 html: 'Cell C content',
75 html: 'Cell D content'
77 renderTo: Ext.getBody()
79 </code></pre>
82 Ext.define('Ext.layout.container.Table', {
84 /* Begin Definitions */
86 alias: ['layout.table'],
87 extend: 'Ext.layout.container.Auto',
88 alternateClassName: 'Ext.layout.TableLayout',
92 <span id='Ext-layout-container-Table-cfg-columns'> /**
93 </span> * @cfg {Number} columns
94 * The total number of columns to create in the table for this layout. If not specified, all Components added to
95 * this layout will be rendered into a single row using one column per Component.
103 // Table layout is a self-sizing layout. When an item of for example, a dock layout, the Panel must expand to accommodate
104 // a table layout. See in particular AbstractDock::onLayout for use of this flag.
107 clearEl: true, // Base class will not create it if already truthy. Not needed in tables.
109 targetCls: Ext.baseCSSPrefix + 'table-layout-ct',
110 tableCls: Ext.baseCSSPrefix + 'table-layout',
111 cellCls: Ext.baseCSSPrefix + 'table-layout-cell',
113 <span id='Ext-layout-container-Table-cfg-tableAttrs'> /**
114 </span> * @cfg {Object} tableAttrs
115 * <p>An object containing properties which are added to the {@link Ext.core.DomHelper DomHelper} specification
116 * used to create the layout's <tt>&lt;table&gt;</tt> element. Example:</p><pre><code>
128 }</code></pre>
132 <span id='Ext-layout-container-Table-method-renderItems'> /**
134 * Iterates over all passed items, ensuring they are rendered in a cell in the proper
135 * location in the table structure.
137 renderItems: function(items) {
138 var tbody = this.getTable().tBodies[0],
142 cells, curCell, rowIdx, cellIdx, item, trEl, tdEl, itemCt;
144 // Calculate the correct cell structure for the current items
145 cells = this.calculateCells(items);
147 // Loop over each cell and compare to the current cells in the table, inserting/
148 // removing/moving cells as needed, and making sure each item is rendered into
150 for (; i < len; i++) {
152 rowIdx = curCell.rowIdx;
153 cellIdx = curCell.cellIdx;
156 // If no row present, create and insert one
159 trEl = tbody.insertRow(rowIdx);
162 // If no cell present, create and insert one
163 itemCt = tdEl = Ext.get(trEl.cells[cellIdx] || trEl.insertCell(cellIdx));
164 if (this.needsDivWrap()) { //create wrapper div if needed - see docs below
165 itemCt = tdEl.first() || tdEl.createChild({tag: 'div'});
166 itemCt.setWidth(null);
169 // Render or move the component into the cell
170 if (!item.rendered) {
171 this.renderItem(item, itemCt, 0);
173 else if (!this.isValidParent(item, itemCt, 0)) {
174 this.moveItem(item, itemCt, 0);
177 // Set the cell properties
179 colSpan: item.colspan || 1,
180 rowSpan: item.rowspan || 1,
181 id: item.cellId || '',
182 cls: this.cellCls + ' ' + (item.cellCls || '')
185 // If at the end of a row, remove any extra cells
186 if (!cells[i + 1] || cells[i + 1].rowIdx !== rowIdx) {
188 while (trEl.cells[cellIdx]) {
189 trEl.deleteCell(cellIdx);
194 // Delete any extra rows
196 while (tbody.rows[rowIdx]) {
197 tbody.deleteRow(rowIdx);
201 afterLayout: function() {
204 if (this.needsDivWrap()) {
205 // set wrapper div width to match layed out item - see docs below
206 Ext.Array.forEach(this.getLayoutItems(), function(item) {
207 Ext.fly(item.el.dom.parentNode).setWidth(item.getWidth());
212 <span id='Ext-layout-container-Table-method-calculateCells'> /**
214 * Determine the row and cell indexes for each component, taking into consideration
215 * the number of columns and each item's configured colspan/rowspan values.
216 * @param {Array} items The layout components
217 * @return {Array} List of row and cell indexes for each of the components
219 calculateCells: function(items) {
224 totalCols = this.columns || Infinity,
225 rowspans = [], //rolling list of active rowspans for each column
230 for (; i < len; i++) {
233 // Find the first available row/col slot not taken up by a spanning cell
234 while (colIdx >= totalCols || rowspans[colIdx] > 0) {
235 if (colIdx >= totalCols) {
236 // move down to next row
241 // decrement all rowspans
242 for (j = 0; j < totalCols; j++) {
243 if (rowspans[j] > 0) {
252 // Add the cell info to the list
259 rowspans[colIdx] = item.rowspan || 1;
260 colIdx += item.colspan || 1;
267 <span id='Ext-layout-container-Table-method-getTable'> /**
269 * Return the layout's table element, creating it if necessary.
271 getTable: function() {
272 var table = this.table;
274 table = this.table = this.getTarget().createChild(
277 role: 'presentation',
279 cellspacing: 0, //TODO should this be specified or should CSS handle it?
288 <span id='Ext-layout-container-Table-method-needsDivWrap'> /**
290 * Opera 10.5 has a bug where if a table cell's child has box-sizing:border-box and padding, it
291 * will include that padding in the size of the cell, making it always larger than the
292 * shrink-wrapped size of its contents. To get around this we have to wrap the contents in a div
293 * and then set that div's width to match the item rendered within it afterLayout. This method
294 * determines whether we need the wrapper div; it currently does a straight UA sniff as this bug
295 * seems isolated to just Opera 10.5, but feature detection could be added here if needed.
297 needsDivWrap: function() {
298 return Ext.isOpera10_5;