1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-grid.plugin.HeaderResizer'>/**
2 </span> * @class Ext.grid.plugin.HeaderResizer
3 * @extends Ext.util.Observable
5 * Plugin to add header resizing functionality to a HeaderContainer.
6 * Always resizing header to the left of the splitter you are resizing.
8 * Todo: Consider RTL support, columns would always calculate to the right of
9 * the splitter instead of to the left.
11 Ext.define('Ext.grid.plugin.HeaderResizer', {
12 extend: 'Ext.util.Observable',
13 requires: ['Ext.dd.DragTracker', 'Ext.util.Region'],
14 alias: 'plugin.gridheaderresizer',
18 <span id='Ext-grid.plugin.HeaderResizer-cfg-dynamic'> /**
19 </span> * @cfg {Boolean} dynamic
20 * Set to true to resize on the fly rather than using a proxy marker. Defaults to false.
26 colHeaderCls: Ext.baseCSSPrefix + 'column-header',
30 wResizeCursor: 'col-resize',
31 eResizeCursor: 'col-resize',
32 // not using w and e resize bc we are only ever resizing one
34 //wResizeCursor: Ext.isWebKit ? 'w-resize' : 'col-resize',
35 //eResizeCursor: Ext.isWebKit ? 'e-resize' : 'col-resize',
37 init: function(headerCt) {
38 this.headerCt = headerCt;
39 headerCt.on('render', this.afterHeaderRender, this, {single: true});
42 <span id='Ext-grid.plugin.HeaderResizer-method-destroy'> /**
44 * AbstractComponent calls destroy on all its plugins at destroy time.
48 this.tracker.destroy();
52 afterHeaderRender: function() {
53 var headerCt = this.headerCt,
56 headerCt.mon(el, 'mousemove', this.onHeaderCtMouseMove, this);
58 this.tracker = Ext.create('Ext.dd.DragTracker', {
59 disabled: this.disabled,
60 onBeforeStart: Ext.Function.bind(this.onBeforeStart, this),
61 onStart: Ext.Function.bind(this.onStart, this),
62 onDrag: Ext.Function.bind(this.onDrag, this),
63 onEnd: Ext.Function.bind(this.onEnd, this),
70 // As we mouse over individual headers, change the cursor to indicate
71 // that resizing is available, and cache the resize target header for use
72 // if/when they mousedown.
73 onHeaderCtMouseMove: function(e, t) {
74 if (this.headerCt.dragging) {
76 this.activeHd.el.dom.style.cursor = '';
80 var headerEl = e.getTarget('.' + this.colHeaderCls, 3, true),
81 overHeader, resizeHeader;
84 overHeader = Ext.getCmp(headerEl.id);
86 // On left edge, we are resizing the previous non-hidden, base level column.
87 if (overHeader.isOnLeftEdge(e)) {
88 resizeHeader = overHeader.previousNode('gridcolumn:not([hidden]):not([isGroupHeader])');
90 // Else, if on the right edge, we're resizing the column we are over
91 else if (overHeader.isOnRightEdge(e)) {
92 resizeHeader = overHeader;
94 // Between the edges: we are not resizing
101 // If we're attempting to resize a group header, that cannot be resized,
102 // so find its last base level column header; Group headers are sized
103 // by the size of their child headers.
104 if (resizeHeader.isGroupHeader) {
105 resizeHeader = resizeHeader.getVisibleGridColumns();
106 resizeHeader = resizeHeader[resizeHeader.length - 1];
109 if (resizeHeader && !resizeHeader.fixed) {
110 this.activeHd = resizeHeader;
111 overHeader.el.dom.style.cursor = this.eResizeCursor;
115 overHeader.el.dom.style.cursor = '';
116 delete this.activeHd;
122 // only start when there is an activeHd
123 onBeforeStart : function(e){
124 var t = e.getTarget();
125 // cache the activeHd because it will be cleared.
126 this.dragHd = this.activeHd;
128 if (!!this.dragHd && !Ext.fly(t).hasCls('x-column-header-trigger') && !this.headerCt.dragging) {
129 //this.headerCt.dragging = true;
130 this.tracker.constrainTo = this.getConstrainRegion();
133 this.headerCt.dragging = false;
138 // get the region to constrain to, takes into account max and min col widths
139 getConstrainRegion: function() {
140 var dragHdEl = this.dragHd.el,
141 region = Ext.util.Region.getRegion(dragHdEl);
143 return region.adjust(
145 this.maxColWidth - dragHdEl.getWidth(),
151 // initialize the left and right hand side markers around
152 // the header that we are resizing
153 onStart: function(e){
156 dragHdEl = dragHd.el,
157 width = dragHdEl.getWidth(),
158 headerCt = me.headerCt,
161 if (me.dragHd && !Ext.fly(t).hasCls('x-column-header-trigger')) {
162 headerCt.dragging = true;
165 me.origWidth = width;
167 // setup marker proxies
169 var xy = dragHdEl.getXY(),
170 gridSection = headerCt.up('[scrollerOwner]'),
171 dragHct = me.dragHd.up(':not([isGroupHeader])'),
172 firstSection = dragHct.up(),
173 lhsMarker = gridSection.getLhsMarker(),
174 rhsMarker = gridSection.getRhsMarker(),
175 el = rhsMarker.parent(),
176 offsetLeft = el.getLeft(true),
177 offsetTop = el.getTop(true),
178 topLeft = el.translatePoints(xy),
179 markerHeight = firstSection.body.getHeight() + headerCt.getHeight(),
180 top = topLeft.top - offsetTop;
182 lhsMarker.setTop(top);
183 rhsMarker.setTop(top);
184 lhsMarker.setHeight(markerHeight);
185 rhsMarker.setHeight(markerHeight);
186 lhsMarker.setLeft(topLeft.left - offsetLeft);
187 rhsMarker.setLeft(topLeft.left + width - offsetLeft);
191 // synchronize the rhsMarker with the mouse movement
194 var xy = this.tracker.getXY('point'),
195 gridSection = this.headerCt.up('[scrollerOwner]'),
196 rhsMarker = gridSection.getRhsMarker(),
197 el = rhsMarker.parent(),
198 topLeft = el.translatePoints(xy),
199 offsetLeft = el.getLeft(true);
201 rhsMarker.setLeft(topLeft.left - offsetLeft);
202 // Resize as user interacts
209 this.headerCt.dragging = false;
212 var dragHd = this.dragHd,
213 gridSection = this.headerCt.up('[scrollerOwner]'),
214 lhsMarker = gridSection.getLhsMarker(),
215 rhsMarker = gridSection.getRhsMarker(),
216 currWidth = dragHd.getWidth(),
217 offset = this.tracker.getOffset('point'),
221 lhsMarker.setLeft(offscreen);
222 rhsMarker.setLeft(offscreen);
228 doResize: function() {
230 var dragHd = this.dragHd,
232 offset = this.tracker.getOffset('point');
239 // If HeaderContainer is configured forceFit, inhibit upstream layout notification, so that
240 // we can also shrink the following Header by an equal amount, and *then* inform the upstream layout.
241 if (this.headerCt.forceFit) {
242 nextHd = dragHd.nextNode('gridcolumn:not([hidden]):not([isGroupHeader])');
244 this.headerCt.componentLayout.layoutBusy = true;
248 // Non-flexed Headers may never be squeezed in the event of a shortfall so
249 // always set the minWidth to their current width.
250 dragHd.minWidth = this.origWidth + offset[0];
251 dragHd.setWidth(dragHd.minWidth);
253 // In the case of forceFit, change the following Header width.
254 // Then apply the two width changes by laying out the owning HeaderContainer
257 nextHd.setWidth(nextHd.getWidth() - offset[0]);
258 this.headerCt.componentLayout.layoutBusy = false;
259 this.headerCt.doComponentLayout();
264 disable: function() {
265 this.disabled = true;
267 this.tracker.disable();
272 this.disabled = false;
274 this.tracker.enable();
277 });</pre></pre></body></html>