Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / ColumnLayout.html
1 <html>
2 <head>
3   <title>The source code</title>
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
6 </head>
7 <body  onload="prettyPrint();">
8     <pre class="prettyprint lang-js">/*!
9  * Ext JS Library 3.0.3
10  * Copyright(c) 2006-2009 Ext JS, LLC
11  * licensing@extjs.com
12  * http://www.extjs.com/license
13  */
14 <div id="cls-Ext.layout.ColumnLayout"></div>/**\r
15  * @class Ext.layout.ColumnLayout\r
16  * @extends Ext.layout.ContainerLayout\r
17  * <p>This is the layout style of choice for creating structural layouts in a multi-column format where the width of\r
18  * each column can be specified as a percentage or fixed width, but the height is allowed to vary based on the content.\r
19  * This class is intended to be extended or created via the layout:'column' {@link Ext.Container#layout} config,\r
20  * and should generally not need to be created directly via the new keyword.</p>\r
21  * <p>ColumnLayout does not have any direct config options (other than inherited ones), but it does support a\r
22  * specific config property of <b><tt>columnWidth</tt></b> that can be included in the config of any panel added to it.  The\r
23  * layout will use the columnWidth (if present) or width of each panel during layout to determine how to size each panel.\r
24  * If width or columnWidth is not specified for a given panel, its width will default to the panel's width (or auto).</p>\r
25  * <p>The width property is always evaluated as pixels, and must be a number greater than or equal to 1.\r
26  * The columnWidth property is always evaluated as a percentage, and must be a decimal value greater than 0 and\r
27  * less than 1 (e.g., .25).</p>\r
28  * <p>The basic rules for specifying column widths are pretty simple.  The logic makes two passes through the\r
29  * set of contained panels.  During the first layout pass, all panels that either have a fixed width or none\r
30  * specified (auto) are skipped, but their widths are subtracted from the overall container width.  During the second\r
31  * pass, all panels with columnWidths are assigned pixel widths in proportion to their percentages based on\r
32  * the total <b>remaining</b> container width.  In other words, percentage width panels are designed to fill the space\r
33  * left over by all the fixed-width and/or auto-width panels.  Because of this, while you can specify any number of columns\r
34  * with different percentages, the columnWidths must always add up to 1 (or 100%) when added together, otherwise your\r
35  * layout may not render as expected.  Example usage:</p>\r
36  * <pre><code>\r
37 // All columns are percentages -- they must add up to 1\r
38 var p = new Ext.Panel({\r
39     title: 'Column Layout - Percentage Only',\r
40     layout:'column',\r
41     items: [{\r
42         title: 'Column 1',\r
43         columnWidth: .25 \r
44     },{\r
45         title: 'Column 2',\r
46         columnWidth: .6\r
47     },{\r
48         title: 'Column 3',\r
49         columnWidth: .15\r
50     }]\r
51 });\r
52 \r
53 // Mix of width and columnWidth -- all columnWidth values must add up\r
54 // to 1. The first column will take up exactly 120px, and the last two\r
55 // columns will fill the remaining container width.\r
56 var p = new Ext.Panel({\r
57     title: 'Column Layout - Mixed',\r
58     layout:'column',\r
59     items: [{\r
60         title: 'Column 1',\r
61         width: 120\r
62     },{\r
63         title: 'Column 2',\r
64         columnWidth: .8\r
65     },{\r
66         title: 'Column 3',\r
67         columnWidth: .2\r
68     }]\r
69 });\r
70 </code></pre>\r
71  */\r
72 Ext.layout.ColumnLayout = Ext.extend(Ext.layout.ContainerLayout, {\r
73     // private\r
74     monitorResize:true,\r
75     \r
76     extraCls: 'x-column',\r
77 \r
78     scrollOffset : 0,\r
79 \r
80     // private\r
81     isValidParent : function(c, target){\r
82         return (c.getPositionEl ? c.getPositionEl() : c.getEl()).dom.parentNode == this.innerCt.dom;\r
83     },\r
84 \r
85     // private\r
86     onLayout : function(ct, target){\r
87         var cs = ct.items.items, len = cs.length, c, i;\r
88 \r
89         if(!this.innerCt){\r
90             target.addClass('x-column-layout-ct');\r
91 \r
92             // the innerCt prevents wrapping and shuffling while\r
93             // the container is resizing\r
94             this.innerCt = target.createChild({cls:'x-column-inner'});\r
95             this.innerCt.createChild({cls:'x-clear'});\r
96         }\r
97         this.renderAll(ct, this.innerCt);\r
98 \r
99         var size = Ext.isIE && target.dom != Ext.getBody().dom ? target.getStyleSize() : target.getViewSize();\r
100 \r
101         if(size.width < 1 && size.height < 1){ // display none?\r
102             return;\r
103         }\r
104 \r
105         var w = size.width - target.getPadding('lr') - this.scrollOffset,\r
106             h = size.height - target.getPadding('tb'),\r
107             pw = w;\r
108 \r
109         this.innerCt.setWidth(w);\r
110         \r
111         // some columns can be percentages while others are fixed\r
112         // so we need to make 2 passes\r
113 \r
114         for(i = 0; i < len; i++){\r
115             c = cs[i];\r
116             if(!c.columnWidth){\r
117                 pw -= (c.getSize().width + c.getEl().getMargins('lr'));\r
118             }\r
119         }\r
120 \r
121         pw = pw < 0 ? 0 : pw;\r
122 \r
123         for(i = 0; i < len; i++){\r
124             c = cs[i];\r
125             if(c.columnWidth){\r
126                 c.setSize(Math.floor(c.columnWidth*pw) - c.getEl().getMargins('lr'));\r
127             }\r
128         }\r
129     }\r
130     \r
131     <div id="prop-Ext.layout.ColumnLayout-activeItem"></div>/**\r
132      * @property activeItem\r
133      * @hide\r
134      */\r
135 });\r
136 \r
137 Ext.Container.LAYOUTS['column'] = Ext.layout.ColumnLayout;</pre>
138 </body>
139 </html>