Fix #6874 - Grid column resize
[roojs1] / Roo / grid / SplitDragZone.js
1 /*
2  * Based on:
3  * Ext JS Library 1.1.1
4  * Copyright(c) 2006-2007, Ext JS, LLC.
5  *
6  * Originally Released Under LGPL - original licence link has changed is not relivant.
7  *
8  * Fork - LGPL
9  * <script type="text/javascript">
10  */
11  /**
12  * @extends Roo.dd.DDProxy
13  * @class Roo.grid.SplitDragZone
14  * Support for Column Header resizing
15  * @constructor
16  * @param {Object} config
17  */
18 // private
19 // This is a support class used internally by the Grid components
20 Roo.grid.SplitDragZone = function(grid, hd, hd2){
21     this.grid = grid;
22     this.view = grid.getView();
23     this.proxy = this.view.resizeProxy;
24     Roo.grid.SplitDragZone.superclass.constructor.call(
25         this,
26         hd, // ID
27         "gridSplitters" + this.grid.getGridEl().id, // SGROUP
28         {  // CONFIG
29             dragElId : Roo.id(this.proxy.dom),
30             resizeFrame:false
31         }
32     );
33     
34     this.setHandleElId(Roo.id(hd));
35     if (hd2 !== false) {
36         this.setOuterHandleElId(Roo.id(hd2));
37     }
38     
39     this.scroll = false;
40 };
41 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
42     fly: Roo.Element.fly,
43
44     b4StartDrag : function(x, y){
45         this.view.headersDisabled = true;
46         var h = this.view.mainWrap ? this.view.mainWrap.getHeight() : (
47                     this.view.headEl.getHeight() + this.view.bodyEl.getHeight()
48         );
49         this.proxy.setHeight(h);
50         
51         // for old system colWidth really stored the actual width?
52         // in bootstrap we tried using xs/ms/etc.. to do % sizing?
53         // which in reality did not work.. - it worked only for fixed sizes
54         // for resizable we need to use actual sizes.
55         var w = this.cm.getColumnWidth(this.cellIndex);
56         if (!this.view.mainWrap) {
57             // bootstrap.
58             w = this.view.getHeaderIndex(this.cellIndex).getWidth();
59         }
60         
61         
62         
63         // this was w-this.grid.minColumnWidth;
64         // doesnt really make sense? - w = thie curren width or the rendered one?
65         var minw = Math.max(w-this.grid.minColumnWidth, 0);
66         this.resetConstraints();
67         this.setXConstraint(minw, 1000);
68         this.setYConstraint(0, 0);
69         this.minX = x - minw;
70         this.maxX = x + 1000;
71         this.startPos = x;
72         if (!this.view.mainWrap) { // this is Bootstrap code..
73             this.getDragEl().style.display='block';
74         }
75         
76         Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
77     },
78
79
80     handleMouseDown : function(e){
81         ev = Roo.EventObject.setEvent(e);
82         var t = this.fly(ev.getTarget());
83         if(t.hasClass("x-grid-split")){
84             this.cellIndex = this.view.getCellIndex(t.dom);
85             this.split = t.dom;
86             this.cm = this.grid.colModel;
87             if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
88                 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
89             }
90         }
91     },
92
93     endDrag : function(e){
94         this.view.headersDisabled = false;
95         var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
96         var diff = endX - this.startPos;
97         // 
98         var w = this.cm.getColumnWidth(this.cellIndex);
99         if (!this.view.mainWrap) {
100             w = 0;
101         }
102         this.view.onColumnSplitterMoved(this.cellIndex, w+diff);
103     },
104
105     autoOffset : function(){
106         this.setDelta(0,0);
107     }
108 });