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-container-Container'>/**
19 </span> * @class Ext.container.Container
20 * @extends Ext.container.AbstractContainer
21 * <p>Base class for any {@link Ext.Component} that may contain other Components. Containers handle the
22 * basic behavior of containing items, namely adding, inserting and removing items.</p>
24 * <p>The most commonly used Container classes are {@link Ext.panel.Panel}, {@link Ext.window.Window} and {@link Ext.tab.Panel}.
25 * If you do not need the capabilities offered by the aforementioned classes you can create a lightweight
26 * Container to be encapsulated by an HTML element to your specifications by using the
27 * <code><b>{@link Ext.Component#autoEl autoEl}</b></code> config option.</p>
29 * {@img Ext.Container/Ext.Container.png Ext.Container component}
30 * <p>The code below illustrates how to explicitly create a Container:<pre><code>
31 // explicitly create a Container
32 Ext.create('Ext.container.Container', {
37 renderTo: Ext.getBody(),
39 style: {borderColor:'#000000', borderStyle:'solid', borderWidth:'1px'},
42 // implicitly create Container by specifying xtype
52 fieldLabel: 'Start date'
56 fieldLabel: 'End date'
59 </code></pre></p>
61 * <p><u><b>Layout</b></u></p>
62 * <p>Container classes delegate the rendering of child Components to a layout
63 * manager class which must be configured into the Container using the
64 * <code><b>{@link #layout}</b></code> configuration property.</p>
65 * <p>When either specifying child <code>{@link #items}</code> of a Container,
66 * or dynamically {@link #add adding} Components to a Container, remember to
67 * consider how you wish the Container to arrange those child elements, and
68 * whether those child elements need to be sized using one of Ext's built-in
69 * <b><code>{@link #layout}</code></b> schemes. By default, Containers use the
70 * {@link Ext.layout.container.Auto Auto} scheme which only
71 * renders child components, appending them one after the other inside the
72 * Container, and <b>does not apply any sizing</b> at all.</p>
73 * <p>A common mistake is when a developer neglects to specify a
74 * <b><code>{@link #layout}</code></b> (e.g. widgets like GridPanels or
75 * TreePanels are added to Containers for which no <code><b>{@link #layout}</b></code>
76 * has been specified). If a Container is left to use the default
77 * {Ext.layout.container.Auto Auto} scheme, none of its
78 * child components will be resized, or changed in any way when the Container
79 * is resized.</p>
80 * <p>Certain layout managers allow dynamic addition of child components.
81 * Those that do include {@link Ext.layout.container.Card},
82 * {@link Ext.layout.container.Anchor}, {@link Ext.layout.container.VBox}, {@link Ext.layout.container.HBox}, and
83 * {@link Ext.layout.container.Table}. For example:<pre><code>
84 // Create the GridPanel.
85 var myNewGrid = new Ext.grid.Panel({
88 title: 'Results', // the title becomes the title of the tab
91 myTabPanel.add(myNewGrid); // {@link Ext.tab.Panel} implicitly uses {@link Ext.layout.container.Card Card}
92 myTabPanel.{@link Ext.tab.Panel#setActiveTab setActiveTab}(myNewGrid);
93 * </code></pre></p>
94 * <p>The example above adds a newly created GridPanel to a TabPanel. Note that
95 * a TabPanel uses {@link Ext.layout.container.Card} as its layout manager which
96 * means all its child items are sized to {@link Ext.layout.container.Fit fit}
97 * exactly into its client area.
98 * <p><b><u>Overnesting is a common problem</u></b>.
99 * An example of overnesting occurs when a GridPanel is added to a TabPanel
100 * by wrapping the GridPanel <i>inside</i> a wrapping Panel (that has no
101 * <code><b>{@link #layout}</b></code> specified) and then add that wrapping Panel
102 * to the TabPanel. The point to realize is that a GridPanel <b>is</b> a
103 * Component which can be added directly to a Container. If the wrapping Panel
104 * has no <code><b>{@link #layout}</b></code> configuration, then the overnested
105 * GridPanel will not be sized as expected.<p>
107 * <p><u><b>Adding via remote configuration</b></u></p>
109 * <p>A server side script can be used to add Components which are generated dynamically on the server.
110 * An example of adding a GridPanel to a TabPanel where the GridPanel is generated by the server
111 * based on certain parameters:
112 * </p><pre><code>
113 // execute an Ajax request to invoke server side script:
115 url: 'gen-invoice-grid.php',
116 // send additional parameters to instruct server script
118 startDate: Ext.getCmp('start-date').getValue(),
119 endDate: Ext.getCmp('end-date').getValue()
121 // process the response object to add it to the TabPanel:
122 success: function(xhr) {
123 var newComponent = eval(xhr.responseText); // see discussion below
124 myTabPanel.add(newComponent); // add the component to the TabPanel
125 myTabPanel.setActiveTab(newComponent);
127 failure: function() {
128 Ext.Msg.alert("Grid create failed", "Server communication failure");
131 </code></pre>
132 * <p>The server script needs to return a JSON representation of a configuration object, which, when decoded
133 * will return a config object with an {@link Ext.Component#xtype xtype}. The server might return the following
134 * JSON:</p><pre><code>
136 "xtype": 'grid',
137 "title": 'Invoice Report',
139 "model": 'Invoice',
141 "type": 'ajax',
142 "url": 'get-invoice-data.php',
143 "reader": {
144 "type": 'json'
145 "record": 'transaction',
146 "idProperty": 'id',
147 "totalRecords": 'total'
150 "autoLoad": {
151 "params": {
152 "startDate": '01/01/2008',
153 "endDate": '01/31/2008'
157 "headers": [
158 {"header": "Customer", "width": 250, "dataIndex": 'customer', "sortable": true},
159 {"header": "Invoice Number", "width": 120, "dataIndex": 'invNo', "sortable": true},
160 {"header": "Invoice Date", "width": 100, "dataIndex": 'date', "renderer": Ext.util.Format.dateRenderer('M d, y'), "sortable": true},
161 {"header": "Value", "width": 120, "dataIndex": 'value', "renderer": 'usMoney', "sortable": true}
164 </code></pre>
165 * <p>When the above code fragment is passed through the <code>eval</code> function in the success handler
166 * of the Ajax request, the result will be a config object which, when added to a Container, will cause instantiation
167 * of a GridPanel. <b>Be sure that the Container is configured with a layout which sizes and positions the child items to your requirements.</b></p>
168 * <p>Note: since the code above is <i>generated</i> by a server script, the <code>autoLoad</code> params for
169 * the Store, the user's preferred date format, the metadata to allow generation of the Model layout, and the ColumnModel
170 * can all be generated into the code since these are all known on the server.</p>
174 Ext.define('Ext.container.Container', {
175 extend: 'Ext.container.AbstractContainer',
176 alias: 'widget.container',
177 alternateClassName: 'Ext.Container',
179 <span id='Ext-container-Container-method-getChildByElement'> /**
180 </span> * Return the immediate child Component in which the passed element is located.
181 * @param el The element to test.
182 * @return {Component} The child item which contains the passed element.
184 getChildByElement: function(el) {
188 it = this.items.items,
192 for (; i < ln; i++) {
194 itemEl = item.getEl();
195 if ((itemEl.dom === el) || itemEl.contains(el)) {