4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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-grid-ColumnLayout'>/**
19 </span> * @class Ext.grid.ColumnLayout
20 * @extends Ext.layout.container.HBox
23 * <p>This class is used only by the grid's HeaderContainer docked child.</p>
25 * <p>It adds the ability to shrink the vertical size of the inner container element back if a grouped
26 * column header has all its child columns dragged out, and the whole HeaderContainer needs to shrink back down.</p>
28 * <p>Also, after every layout, after all headers have attained their 'stretchmax' height, it goes through and calls
29 * <code>setPadding</code> on the columns so that they lay out correctly.</p>
31 Ext.define('Ext.grid.ColumnLayout', {
32 extend: 'Ext.layout.container.HBox',
33 alias: 'layout.gridcolumn',
40 // Height-stretched innerCt must be able to revert back to unstretched height
41 clearInnerCtOnLayout: true,
43 beforeLayout: function() {
46 items = me.getLayoutItems(),
51 // Scrollbar offset defined by width of any vertical scroller in the owning grid
52 if (!Ext.isDefined(me.availableSpaceOffset)) {
53 s = me.owner.up('tablepanel').verticalScroller;
54 me.availableSpaceOffset = s ? s.width-1 : 0;
57 returnValue = me.callParent(arguments);
59 // Size to a sane minimum height before possibly being stretched to accommodate grouped headers
60 me.innerCt.setHeight(23);
62 // Unstretch child items before the layout which stretches them.
63 for (; i < len; i++) {
68 item.titleContainer.setStyle({
72 if (item.componentLayout && item.componentLayout.lastComponentSize) {
73 item.componentLayout.lastComponentSize.height = item.el.dom.offsetHeight;
79 // Override to enforce the forceFit config.
80 calculateChildBoxes: function(visibleItems, targetSize) {
82 calculations = me.callParent(arguments),
83 boxes = calculations.boxes,
84 metaData = calculations.meta,
85 len = boxes.length, i = 0, box, item;
87 if (targetSize.width && !me.isHeader) {
88 // If configured forceFit then all columns will be flexed
89 if (me.owner.forceFit) {
91 for (; i < len; i++) {
95 // Set a sane minWidth for the Box layout to be able to squeeze flexed Headers down to.
96 item.minWidth = Ext.grid.plugin.HeaderResizer.prototype.minColWidth;
98 // For forceFit, just use allocated width as the flex value, and the proportions
99 // will end up the same whatever HeaderContainer width they are being forced into.
100 item.flex = box.width;
103 // Recalculate based upon all columns now being flexed instead of sized.
104 calculations = me.callParent(arguments);
106 else if (metaData.tooNarrow) {
107 targetSize.width = metaData.desiredSize;
114 afterLayout: function() {
128 me.callParent(arguments);
130 // Set up padding in items
131 if (!me.owner.hideHeaders) {
133 // If this is one HeaderContainer of a pair in a side-by-side locking view, then find the height
134 // of the highest one, and sync the other one to that height.
135 if (owner.lockableInjected) {
136 topGrid = owner.up('tablepanel').up('tablepanel');
137 bothHeaderCts = topGrid.query('headercontainer:not([isHeader])');
138 otherHeaderCt = (bothHeaderCts[0] === owner) ? bothHeaderCts[1] : bothHeaderCts[0];
140 // Both sides must be rendered for this syncing operation to work.
141 if (!otherHeaderCt.rendered) {
145 // Get the height of the highest of both HeaderContainers
146 otherHeight = otherHeaderCt.layout.getRenderTarget().getViewSize().height;
150 thisHeight = this.getRenderTarget().getViewSize().height;
155 // Prevent recursion back into here when the "other" grid, after adjusting to the new hight of its headerCt, attempts to inform its ownerCt
156 // Block the upward notification by flagging the top grid's component layout as busy.
157 topGrid.componentLayout.layoutBusy = true;
159 // Assume that the correct header height is the height of this HeaderContainer
160 headerHeight = thisHeight;
162 // Synch the height of the smaller HeaderContainer to the height of the highest one.
163 if (thisHeight > otherHeight) {
164 otherHeaderCt.layout.align = 'stretch';
165 otherHeaderCt.setCalculatedSize(otherHeaderCt.getWidth(), owner.getHeight(), otherHeaderCt.ownerCt);
166 delete otherHeaderCt.layout.align;
167 modifiedGrid = otherHeaderCt.up('tablepanel');
168 } else if (otherHeight > thisHeight) {
169 headerHeight = otherHeight;
170 this.align = 'stretch';
171 owner.setCalculatedSize(owner.getWidth(), otherHeaderCt.getHeight(), owner.ownerCt);
173 modifiedGrid = owner.up('tablepanel');
175 topGrid.componentLayout.layoutBusy = false;
177 // Gather all Header items across both Grids.
178 items = bothHeaderCts[0].layout.getLayoutItems().concat(bothHeaderCts[1].layout.getLayoutItems());
180 headerHeight = this.getRenderTarget().getViewSize().height;
181 items = me.getLayoutItems();
185 for (; i < len; i++) {
186 items[i].setPadding(headerHeight);
189 // Size the View within the grid which has had its HeaderContainer entallened (That's a perfectly cromulent word BTW)
191 setTimeout(function() {
192 modifiedGrid.doLayout();
198 // FIX: when flexing we actually don't have enough space as we would
199 // typically because of the scrollOffset on the GridView, must reserve this
200 updateInnerCtSize: function(tSize, calcs) {
204 // Columns must not account for scroll offset
206 me.tooNarrow = calcs.meta.tooNarrow;
207 extra = (me.reserveOffset ? me.availableSpaceOffset : 0);
209 if (calcs.meta.tooNarrow) {
210 tSize.width = calcs.meta.desiredSize + extra;
212 tSize.width += extra;
216 return me.callParent(arguments);
219 doOwnerCtLayouts: function() {
220 var ownerCt = this.owner.ownerCt;
221 if (!ownerCt.componentLayout.layoutBusy) {
222 ownerCt.doComponentLayout();