2 * Ext JS Library 2.2.1
\r
3 * Copyright(c) 2006-2009, Ext JS, LLC.
\r
4 * licensing@extjs.com
\r
6 * http://extjs.com/license
\r
10 * @class Ext.grid.GridView
\r
11 * @extends Ext.util.Observable
\r
12 * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}.
\r
13 * Methods of this class may be used to access user interface elements to enable
\r
14 * special display effects. Do not change the DOM structure of the user interface.</p>
\r
15 * <p>This class does not provide ways to manipulate the underlying data. The data
\r
16 * model of a Grid is held in an {@link Ext.data.Store}.</p>
\r
18 * @param {Object} config
\r
20 Ext.grid.GridView = function(config){
\r
21 Ext.apply(this, config);
\r
22 // These events are only used internally by the grid components
\r
25 * @event beforerowremoved
\r
26 * Internal UI Event. Fired before a row is removed.
\r
27 * @param {Ext.grid.GridView} view
\r
28 * @param {Number} rowIndex The index of the row to be removed.
\r
29 * @param {Ext.data.Record} record The Record to be removed
\r
33 * @event beforerowsinserted
\r
34 * Internal UI Event. Fired before rows are inserted.
\r
35 * @param {Ext.grid.GridView} view
\r
36 * @param {Number} firstRow The index of the first row to be inserted.
\r
37 * @param {Number} lastRow The index of the last row to be inserted.
\r
39 "beforerowsinserted",
\r
41 * @event beforerefresh
\r
42 * Internal UI Event. Fired before the view is refreshed.
\r
43 * @param {Ext.grid.GridView} view
\r
48 * Internal UI Event. Fired after a row is removed.
\r
49 * @param {Ext.grid.GridView} view
\r
50 * @param {Number} rowIndex The index of the row that was removed.
\r
51 * @param {Ext.data.Record} record The Record that was removed
\r
55 * @event rowsinserted
\r
56 * Internal UI Event. Fired after rows are inserted.
\r
57 * @param {Ext.grid.GridView} view
\r
58 * @param {Number} firstRow The index of the first inserted.
\r
59 * @param {Number} lastRow The index of the last row inserted.
\r
64 * Internal UI Event. Fired after a row has been updated.
\r
65 * @param {Ext.grid.GridView} view
\r
66 * @param {Number} firstRow The index of the row updated.
\r
67 * @param {Ext.data.record} record The Record backing the row updated.
\r
72 * Internal UI Event. Fired after the GridView's body has been refreshed.
\r
73 * @param {Ext.grid.GridView} view
\r
77 Ext.grid.GridView.superclass.constructor.call(this);
\r
80 Ext.extend(Ext.grid.GridView, Ext.util.Observable, {
\r
82 * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom
\r
83 * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b>
\r
84 * parameter. This function should return the CSS class name (or empty string '' for none) that will be added
\r
85 * to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string
\r
86 * (e.g., 'my-class another-class').
\r
87 * @param {Record} record The {@link Ext.data.Record} corresponding to the current row
\r
88 * @param {Number} index The row index
\r
89 * @param {Object} rowParams A config object that is passed to the row template during rendering that allows
\r
90 * customization of various aspects of a body row, if applicable. Note that this object will only be applied if
\r
91 * {@link #enableRowBody} = true, otherwise it will be ignored. The object may contain any of these properties:<ul>
\r
92 * <li><code>body</code> : String <div class="sub-desc">An HTML fragment to be rendered as the cell's body content (defaults to '').</div></li>
\r
93 * <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style string that will be applied to the row's TR style attribute (defaults to '').</div></li>
\r
94 * <li><code>cols</code> : Number <div class="sub-desc">The column count to apply to the body row's TD colspan attribute (defaults to the current
\r
95 * column count of the grid).</div></li>
\r
97 * @param {Store} store The {@link Ext.data.Store} this grid is bound to
\r
98 * @method getRowClass
\r
99 * @return {String} a CSS class name to add to the row.
\r
102 * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body
\r
103 * that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body.
\r
106 * @cfg {String} emptyText Default text to display in the grid body when no rows are available (defaults to '').
\r
109 * @property dragZone
\r
110 * @type Ext.grid.GridDragZone
\r
111 * <p><b>This will only be present if the owning GridPanel was configured with {@link Ext.grid.GridPanel#enableDragDrop enableDragDrop} <tt>true</tt>.</b></p>
\r
112 * <p><b>This will only be present after the owning GridPanel has been rendered</b>.</p>
\r
113 * <p>A customized implementation of a {@link Ext.dd.DragZone DragZone} which provides default implementations of the
\r
114 * template methods of DragZone to enable dragging of the selected rows of a GridPanel. See {@link Ext.grid.GridDragZone} for details.</p>
\r
117 * @cfg {Boolean} deferEmptyText True to defer emptyText being applied until the store's first load
\r
119 deferEmptyText: true,
\r
121 * The amount of space to reserve for the scrollbar (defaults to 19 pixels)
\r
126 * @cfg {Boolean} autoFill True to auto expand the columns to fit the grid <b>when the grid is created</b>.
\r
130 * @cfg {Boolean} forceFit True to auto expand/contract the size of the columns to fit the grid width and prevent horizontal scrolling.
\r
131 * This option overrides any (@link Ext.grid.ColumnModel#width width} settings in the ColumnModel.
\r
135 * The CSS classes applied to a header when it is sorted. (defaults to ["sort-asc", "sort-desc"])
\r
138 sortClasses : ["sort-asc", "sort-desc"],
\r
140 * The text displayed in the "Sort Ascending" menu item
\r
143 sortAscText : "Sort Ascending",
\r
145 * The text displayed in the "Sort Descending" menu item
\r
148 sortDescText : "Sort Descending",
\r
150 * The text displayed in the "Columns" menu item
\r
153 columnsText : "Columns",
\r
157 tdClass: 'x-grid3-cell',
\r
158 hdCls: 'x-grid3-hd',
\r
161 * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to 4)
\r
163 cellSelectorDepth: 4,
\r
165 * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to 10)
\r
167 rowSelectorDepth: 10,
\r
170 * @cfg {String} cellSelector The selector used to find cells internally
\r
172 cellSelector: 'td.x-grid3-cell',
\r
174 * @cfg {String} rowSelector The selector used to find rows internally
\r
176 rowSelector: 'div.x-grid3-row',
\r
178 /* -------------------------------- UI Specific ----------------------------- */
\r
181 initTemplates : function(){
\r
182 var ts = this.templates || {};
\r
184 ts.master = new Ext.Template(
\r
185 '<div class="x-grid3" hidefocus="true">',
\r
186 '<div class="x-grid3-viewport">',
\r
187 '<div class="x-grid3-header"><div class="x-grid3-header-inner"><div class="x-grid3-header-offset">{header}</div></div><div class="x-clear"></div></div>',
\r
188 '<div class="x-grid3-scroller"><div class="x-grid3-body">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>',
\r
190 '<div class="x-grid3-resize-marker"> </div>',
\r
191 '<div class="x-grid3-resize-proxy"> </div>',
\r
197 ts.header = new Ext.Template(
\r
198 '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
\r
199 '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>',
\r
205 ts.hcell = new Ext.Template(
\r
206 '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id} {css}" style="{style}"><div {tooltip} {attr} class="x-grid3-hd-inner x-grid3-hd-{id}" unselectable="on" style="{istyle}">', this.grid.enableHdMenu ? '<a class="x-grid3-hd-btn" href="#"></a>' : '',
\r
207 '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />',
\r
213 ts.body = new Ext.Template('{rows}');
\r
217 ts.row = new Ext.Template(
\r
218 '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">',
\r
219 '<tbody><tr>{cells}</tr>',
\r
220 (this.enableRowBody ? '<tr class="x-grid3-row-body-tr" style="{bodyStyle}"><td colspan="{cols}" class="x-grid3-body-cell" tabIndex="0" hidefocus="on"><div class="x-grid3-row-body">{body}</div></td></tr>' : ''),
\r
221 '</tbody></table></div>'
\r
226 ts.cell = new Ext.Template(
\r
227 '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>',
\r
228 '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>',
\r
235 if(t && typeof t.compile == 'function' && !t.compiled){
\r
236 t.disableFormats = true;
\r
241 this.templates = ts;
\r
242 this.colRe = new RegExp("x-grid3-td-([^\\s]+)", "");
\r
246 fly : function(el){
\r
247 if(!this._flyweight){
\r
248 this._flyweight = new Ext.Element.Flyweight(document.body);
\r
250 this._flyweight.dom = el;
\r
251 return this._flyweight;
\r
255 getEditorParent : function(){
\r
256 return this.scroller.dom;
\r
260 initElements : function(){
\r
261 var E = Ext.Element;
\r
263 var el = this.grid.getGridEl().dom.firstChild;
\r
264 var cs = el.childNodes;
\r
266 this.el = new E(el);
\r
268 this.mainWrap = new E(cs[0]);
\r
269 this.mainHd = new E(this.mainWrap.dom.firstChild);
\r
271 if(this.grid.hideHeaders){
\r
272 this.mainHd.setDisplayed(false);
\r
275 this.innerHd = this.mainHd.dom.firstChild;
\r
276 this.scroller = new E(this.mainWrap.dom.childNodes[1]);
\r
278 this.scroller.setStyle('overflow-x', 'hidden');
\r
281 * The GridView's body Element which encapsulates all rows in the Grid. {@link Ext.Element Element}. Read-only.
\r
282 * <p>This Element is only available after the GridPanel has been rendered.</p>
\r
283 * @type Ext.Element
\r
284 * @property mainBody
\r
286 this.mainBody = new E(this.scroller.dom.firstChild);
\r
288 this.focusEl = new E(this.scroller.dom.childNodes[1]);
\r
289 this.focusEl.swallowEvent("click", true);
\r
291 this.resizeMarker = new E(cs[1]);
\r
292 this.resizeProxy = new E(cs[2]);
\r
296 getRows : function(){
\r
297 return this.hasRows() ? this.mainBody.dom.childNodes : [];
\r
300 // finder methods, used with delegation
\r
303 findCell : function(el){
\r
307 return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth);
\r
311 findCellIndex : function(el, requiredCls){
\r
312 var cell = this.findCell(el);
\r
313 if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){
\r
314 return this.getCellIndex(cell);
\r
320 getCellIndex : function(el){
\r
322 var m = el.className.match(this.colRe);
\r
324 return this.cm.getIndexById(m[1]);
\r
331 findHeaderCell : function(el){
\r
332 var cell = this.findCell(el);
\r
333 return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null;
\r
337 findHeaderIndex : function(el){
\r
338 return this.findCellIndex(el, this.hdCls);
\r
342 * Return the HtmlElement representing the grid row which contains the passed element.
\r
343 * @param {Element} el The target element
\r
344 * @return The row element, or null if the target element is not within a row of this GridView.
\r
346 findRow : function(el){
\r
350 return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth);
\r
354 * Return the index of the grid row which contains the passed element.
\r
355 * @param {Element} el The target element
\r
356 * @return The row index, or <b>false</b> if the target element is not within a row of this GridView.
\r
358 findRowIndex : function(el){
\r
359 var r = this.findRow(el);
\r
360 return r ? r.rowIndex : false;
\r
363 // getter methods for fetching elements dynamically in the grid
\r
366 * Return the <TR> HtmlElement which represents a Grid row for the specified index.
\r
367 * @param {Number} index The row index
\r
368 * @return {HtmlElement} The <TR> element.
\r
370 getRow : function(row){
\r
371 return this.getRows()[row];
\r
375 * Returns the grid's <TD> HtmlElement at the specified coordinates.
\r
376 * @param {Number} row The row index in which to find the cell.
\r
377 * @param {Number} col The column index of the cell.
\r
378 * @return {HtmlElement} The <TD> at the specified coordinates.
\r
380 getCell : function(row, col){
\r
381 return this.getRow(row).getElementsByTagName('td')[col];
\r
385 * Return the <TD> HtmlElement which represents the Grid's header cell for the specified column index.
\r
386 * @param {Number} index The column index
\r
387 * @return {HtmlElement} The <TD> element.
\r
389 getHeaderCell : function(index){
\r
390 return this.mainHd.dom.getElementsByTagName('td')[index];
\r
393 // manipulating elements
\r
395 // private - use getRowClass to apply custom row classes
\r
396 addRowClass : function(row, cls){
\r
397 var r = this.getRow(row);
\r
399 this.fly(r).addClass(cls);
\r
404 removeRowClass : function(row, cls){
\r
405 var r = this.getRow(row);
\r
407 this.fly(r).removeClass(cls);
\r
412 removeRow : function(row){
\r
413 Ext.removeNode(this.getRow(row));
\r
414 this.syncFocusEl(row);
\r
418 removeRows : function(firstRow, lastRow){
\r
419 var bd = this.mainBody.dom;
\r
420 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
\r
421 Ext.removeNode(bd.childNodes[firstRow]);
\r
423 this.syncFocusEl(firstRow);
\r
429 getScrollState : function(){
\r
430 var sb = this.scroller.dom;
\r
431 return {left: sb.scrollLeft, top: sb.scrollTop};
\r
435 restoreScroll : function(state){
\r
436 var sb = this.scroller.dom;
\r
437 sb.scrollLeft = state.left;
\r
438 sb.scrollTop = state.top;
\r
442 * Scrolls the grid to the top
\r
444 scrollToTop : function(){
\r
445 this.scroller.dom.scrollTop = 0;
\r
446 this.scroller.dom.scrollLeft = 0;
\r
450 syncScroll : function(){
\r
451 this.syncHeaderScroll();
\r
452 var mb = this.scroller.dom;
\r
453 this.grid.fireEvent("bodyscroll", mb.scrollLeft, mb.scrollTop);
\r
457 syncHeaderScroll : function(){
\r
458 var mb = this.scroller.dom;
\r
459 this.innerHd.scrollLeft = mb.scrollLeft;
\r
460 this.innerHd.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore)
\r
464 updateSortIcon : function(col, dir){
\r
465 var sc = this.sortClasses;
\r
466 var hds = this.mainHd.select('td').removeClass(sc);
\r
467 hds.item(col).addClass(sc[dir == "DESC" ? 1 : 0]);
\r
471 updateAllColumnWidths : function(){
\r
472 var tw = this.getTotalWidth();
\r
473 var clen = this.cm.getColumnCount();
\r
475 for(var i = 0; i < clen; i++){
\r
476 ws[i] = this.getColumnWidth(i);
\r
479 this.innerHd.firstChild.firstChild.style.width = tw;
\r
481 for(var i = 0; i < clen; i++){
\r
482 var hd = this.getHeaderCell(i);
\r
483 hd.style.width = ws[i];
\r
486 var ns = this.getRows(), row, trow;
\r
487 for(var i = 0, len = ns.length; i < len; i++){
\r
489 row.style.width = tw;
\r
490 if(row.firstChild){
\r
491 row.firstChild.style.width = tw;
\r
492 trow = row.firstChild.rows[0];
\r
493 for (var j = 0; j < clen; j++) {
\r
494 trow.childNodes[j].style.width = ws[j];
\r
499 this.onAllColumnWidthsUpdated(ws, tw);
\r
503 updateColumnWidth : function(col, width){
\r
504 var w = this.getColumnWidth(col);
\r
505 var tw = this.getTotalWidth();
\r
507 this.innerHd.firstChild.firstChild.style.width = tw;
\r
508 var hd = this.getHeaderCell(col);
\r
509 hd.style.width = w;
\r
511 var ns = this.getRows(), row;
\r
512 for(var i = 0, len = ns.length; i < len; i++){
\r
514 row.style.width = tw;
\r
515 if(row.firstChild){
\r
516 row.firstChild.style.width = tw;
\r
517 row.firstChild.rows[0].childNodes[col].style.width = w;
\r
521 this.onColumnWidthUpdated(col, w, tw);
\r
525 updateColumnHidden : function(col, hidden){
\r
526 var tw = this.getTotalWidth();
\r
528 this.innerHd.firstChild.firstChild.style.width = tw;
\r
530 var display = hidden ? 'none' : '';
\r
532 var hd = this.getHeaderCell(col);
\r
533 hd.style.display = display;
\r
535 var ns = this.getRows(), row;
\r
536 for(var i = 0, len = ns.length; i < len; i++){
\r
538 row.style.width = tw;
\r
539 if(row.firstChild){
\r
540 row.firstChild.style.width = tw;
\r
541 row.firstChild.rows[0].childNodes[col].style.display = display;
\r
545 this.onColumnHiddenUpdated(col, hidden, tw);
\r
547 delete this.lastViewWidth; // force recalc
\r
552 doRender : function(cs, rs, ds, startRow, colCount, stripe){
\r
553 var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1;
\r
554 var tstyle = 'width:'+this.getTotalWidth()+';';
\r
556 var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
\r
557 for(var j = 0, len = rs.length; j < len; j++){
\r
558 r = rs[j]; cb = [];
\r
559 var rowIndex = (j+startRow);
\r
560 for(var i = 0; i < colCount; i++){
\r
563 p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
\r
564 p.attr = p.cellAttr = "";
\r
565 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
\r
567 if(p.value == undefined || p.value === "") p.value = " ";
\r
568 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
\r
569 p.css += ' x-grid3-dirty-cell';
\r
571 cb[cb.length] = ct.apply(p);
\r
574 if(stripe && ((rowIndex+1) % 2 == 0)){
\r
575 alt[0] = "x-grid3-row-alt";
\r
578 alt[1] = " x-grid3-dirty-row";
\r
580 rp.cols = colCount;
\r
581 if(this.getRowClass){
\r
582 alt[2] = this.getRowClass(r, rowIndex, rp, ds);
\r
584 rp.alt = alt.join(" ");
\r
585 rp.cells = cb.join("");
\r
586 buf[buf.length] = rt.apply(rp);
\r
588 return buf.join("");
\r
592 processRows : function(startRow, skipStripe){
\r
593 if(this.ds.getCount() < 1){
\r
596 skipStripe = skipStripe || !this.grid.stripeRows;
\r
597 startRow = startRow || 0;
\r
598 var rows = this.getRows();
\r
599 var cls = ' x-grid3-row-alt ';
\r
600 rows[0].className += ' x-grid3-row-first';
\r
601 rows[rows.length - 1].className += ' x-grid3-row-last';
\r
602 for(var i = startRow, len = rows.length; i < len; i++){
\r
606 var isAlt = ((i+1) % 2 == 0);
\r
607 var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1;
\r
608 if(isAlt == hasAlt){
\r
612 row.className += " x-grid3-row-alt";
\r
614 row.className = row.className.replace("x-grid3-row-alt", "");
\r
620 afterRender: function(){
\r
621 this.mainBody.dom.innerHTML = this.renderRows();
\r
622 this.processRows(0, true);
\r
624 if(this.deferEmptyText !== true){
\r
625 this.applyEmptyText();
\r
630 renderUI : function(){
\r
632 var header = this.renderHeaders();
\r
633 var body = this.templates.body.apply({rows:''});
\r
636 var html = this.templates.master.apply({
\r
643 g.getGridEl().dom.innerHTML = html;
\r
645 this.initElements();
\r
647 // get mousedowns early
\r
648 Ext.fly(this.innerHd).on("click", this.handleHdDown, this);
\r
649 this.mainHd.on("mouseover", this.handleHdOver, this);
\r
650 this.mainHd.on("mouseout", this.handleHdOut, this);
\r
651 this.mainHd.on("mousemove", this.handleHdMove, this);
\r
653 this.scroller.on('scroll', this.syncScroll, this);
\r
654 if(g.enableColumnResize !== false){
\r
655 this.splitZone = new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom);
\r
658 if(g.enableColumnMove){
\r
659 this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd);
\r
660 this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom);
\r
663 if(g.enableHdMenu !== false){
\r
664 if(g.enableColumnHide !== false){
\r
665 this.colMenu = new Ext.menu.Menu({id:g.id + "-hcols-menu"});
\r
666 this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
\r
667 this.colMenu.on("itemclick", this.handleHdMenuClick, this);
\r
669 this.hmenu = new Ext.menu.Menu({id: g.id + "-hctx"});
\r
671 {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
\r
672 {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
\r
674 if(g.enableColumnHide !== false){
\r
675 this.hmenu.add('-',
\r
676 {id:"columns", text: this.columnsText, menu: this.colMenu, iconCls: 'x-cols-icon'}
\r
679 this.hmenu.on("itemclick", this.handleHdMenuClick, this);
\r
681 //g.on("headercontextmenu", this.handleHdCtx, this);
\r
684 if(g.trackMouseOver){
\r
685 this.mainBody.on("mouseover", this.onRowOver, this);
\r
686 this.mainBody.on("mouseout", this.onRowOut, this);
\r
688 if(g.enableDragDrop || g.enableDrag){
\r
689 this.dragZone = new Ext.grid.GridDragZone(g, {
\r
690 ddGroup : g.ddGroup || 'GridDD'
\r
694 this.updateHeaderSortState();
\r
699 layout : function(){
\r
700 if(!this.mainBody){
\r
701 return; // not rendered
\r
704 var c = g.getGridEl();
\r
705 var csize = c.getSize(true);
\r
706 var vw = csize.width;
\r
708 if(vw < 20 || csize.height < 20){ // display: none?
\r
713 this.scroller.dom.style.overflow = 'visible';
\r
715 this.scroller.dom.style.position = 'static';
\r
718 this.el.setSize(csize.width, csize.height);
\r
720 var hdHeight = this.mainHd.getHeight();
\r
721 var vh = csize.height - (hdHeight);
\r
723 this.scroller.setSize(vw, vh);
\r
725 this.innerHd.style.width = (vw)+'px';
\r
729 if(this.lastViewWidth != vw){
\r
730 this.fitColumns(false, false);
\r
731 this.lastViewWidth = vw;
\r
735 this.syncHeaderScroll();
\r
737 this.onLayout(vw, vh);
\r
740 // template functions for subclasses and plugins
\r
741 // these functions include precalculated values
\r
742 onLayout : function(vw, vh){
\r
746 onColumnWidthUpdated : function(col, w, tw){
\r
748 this.focusEl.setWidth(tw);
\r
751 onAllColumnWidthsUpdated : function(ws, tw){
\r
753 this.focusEl.setWidth(tw);
\r
756 onColumnHiddenUpdated : function(col, hidden, tw){
\r
758 this.focusEl.setWidth(tw);
\r
761 updateColumnText : function(col, text){
\r
765 afterMove : function(colIndex){
\r
769 /* ----------------------------------- Core Specific -------------------------------------------*/
\r
771 init: function(grid){
\r
774 this.initTemplates();
\r
775 this.initData(grid.store, grid.colModel);
\r
780 getColumnId : function(index){
\r
781 return this.cm.getColumnId(index);
\r
785 renderHeaders : function(){
\r
786 var cm = this.cm, ts = this.templates;
\r
789 var cb = [], sb = [], p = {};
\r
790 var len = cm.getColumnCount();
\r
791 var last = len - 1;
\r
792 for(var i = 0; i < len; i++){
\r
793 p.id = cm.getColumnId(i);
\r
794 p.value = cm.getColumnHeader(i) || "";
\r
795 p.style = this.getColumnStyle(i, true);
\r
796 p.tooltip = this.getColumnTooltip(i);
\r
797 p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
\r
798 if(cm.config[i].align == 'right'){
\r
799 p.istyle = 'padding-right:16px';
\r
803 cb[cb.length] = ct.apply(p);
\r
805 return ts.header.apply({cells: cb.join(""), tstyle:'width:'+this.getTotalWidth()+';'});
\r
809 getColumnTooltip : function(i){
\r
810 var tt = this.cm.getColumnTooltip(i);
\r
812 if(Ext.QuickTips.isEnabled()){
\r
813 return 'ext:qtip="'+tt+'"';
\r
815 return 'title="'+tt+'"';
\r
822 beforeUpdate : function(){
\r
823 this.grid.stopEditing(true);
\r
827 updateHeaders : function(){
\r
828 this.innerHd.firstChild.innerHTML = this.renderHeaders();
\r
832 * Focuses the specified row.
\r
833 * @param {Number} row The row index
\r
835 focusRow : function(row){
\r
836 this.focusCell(row, 0, false);
\r
840 * Focuses the specified cell.
\r
841 * @param {Number} row The row index
\r
842 * @param {Number} col The column index
\r
844 focusCell : function(row, col, hscroll){
\r
845 this.syncFocusEl(this.ensureVisible(row, col, hscroll));
\r
847 this.focusEl.focus();
\r
849 this.focusEl.focus.defer(1, this.focusEl);
\r
853 resolveCell : function(row, col, hscroll){
\r
854 if(typeof row != "number"){
\r
855 row = row.rowIndex;
\r
860 if(row < 0 || row >= this.ds.getCount()){
\r
863 col = (col !== undefined ? col : 0);
\r
865 var rowEl = this.getRow(row), cellEl;
\r
866 if(!(hscroll === false && col === 0)){
\r
867 while(this.cm.isHidden(col)){
\r
870 cellEl = this.getCell(row, col);
\r
873 return {row: rowEl, cell: cellEl};
\r
876 getResolvedXY : function(resolved){
\r
880 var s = this.scroller.dom, c = resolved.cell, r = resolved.row;
\r
881 return c ? Ext.fly(c).getXY() : [this.el.getX(), Ext.fly(r).getY()];
\r
884 syncFocusEl : function(row, col, hscroll){
\r
886 if(!Ext.isArray(xy)){
\r
887 row = Math.min(row, Math.max(0, this.getRows().length-1));
\r
888 xy = this.getResolvedXY(this.resolveCell(row, col, hscroll));
\r
890 this.focusEl.setXY(xy||this.scroller.getXY());
\r
893 ensureVisible : function(row, col, hscroll){
\r
894 var resolved = this.resolveCell(row, col, hscroll);
\r
895 if(!resolved || !resolved.row){
\r
899 var rowEl = resolved.row, cellEl = resolved.cell;
\r
901 var c = this.scroller.dom;
\r
904 var p = rowEl, stop = this.el.dom;
\r
905 while(p && p != stop){
\r
906 ctop += p.offsetTop;
\r
907 p = p.offsetParent;
\r
909 ctop -= this.mainHd.dom.offsetHeight;
\r
911 var cbot = ctop + rowEl.offsetHeight;
\r
913 var ch = c.clientHeight;
\r
914 var stop = parseInt(c.scrollTop, 10);
\r
915 var sbot = stop + ch;
\r
918 c.scrollTop = ctop;
\r
919 }else if(cbot > sbot){
\r
920 c.scrollTop = cbot-ch;
\r
923 if(hscroll !== false){
\r
924 var cleft = parseInt(cellEl.offsetLeft, 10);
\r
925 var cright = cleft + cellEl.offsetWidth;
\r
927 var sleft = parseInt(c.scrollLeft, 10);
\r
928 var sright = sleft + c.clientWidth;
\r
930 c.scrollLeft = cleft;
\r
931 }else if(cright > sright){
\r
932 c.scrollLeft = cright-c.clientWidth;
\r
935 return this.getResolvedXY(resolved);
\r
939 insertRows : function(dm, firstRow, lastRow, isUpdate){
\r
940 if(!isUpdate && firstRow === 0 && lastRow >= dm.getCount()-1){
\r
944 this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
\r
946 var html = this.renderRows(firstRow, lastRow);
\r
947 var before = this.getRow(firstRow);
\r
949 Ext.DomHelper.insertHtml('beforeBegin', before, html);
\r
951 Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html);
\r
954 this.fireEvent("rowsinserted", this, firstRow, lastRow);
\r
955 this.processRows(firstRow);
\r
958 this.syncFocusEl(firstRow);
\r
962 deleteRows : function(dm, firstRow, lastRow){
\r
963 if(dm.getRowCount()<1){
\r
966 this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
\r
968 this.removeRows(firstRow, lastRow);
\r
970 this.processRows(firstRow);
\r
971 this.fireEvent("rowsdeleted", this, firstRow, lastRow);
\r
976 getColumnStyle : function(col, isHeader){
\r
977 var style = !isHeader ? (this.cm.config[col].css || '') : '';
\r
978 style += 'width:'+this.getColumnWidth(col)+';';
\r
979 if(this.cm.isHidden(col)){
\r
980 style += 'display:none;';
\r
982 var align = this.cm.config[col].align;
\r
984 style += 'text-align:'+align+';';
\r
990 getColumnWidth : function(col){
\r
991 var w = this.cm.getColumnWidth(col);
\r
992 if(typeof w == 'number'){
\r
993 return (Ext.isBorderBox ? w : (w-this.borderWidth > 0 ? w-this.borderWidth:0)) + 'px';
\r
999 getTotalWidth : function(){
\r
1000 return this.cm.getTotalWidth()+'px';
\r
1004 fitColumns : function(preventRefresh, onlyExpand, omitColumn){
\r
1005 var cm = this.cm, leftOver, dist, i;
\r
1006 var tw = cm.getTotalWidth(false);
\r
1007 var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset;
\r
1009 if(aw < 20){ // not initialized, so don't screw up the default widths
\r
1012 var extra = aw - tw;
\r
1018 var vc = cm.getColumnCount(true);
\r
1019 var ac = vc-(typeof omitColumn == 'number' ? 1 : 0);
\r
1022 omitColumn = undefined;
\r
1024 var colCount = cm.getColumnCount();
\r
1029 for (i = 0; i < colCount; i++){
\r
1030 if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){
\r
1031 w = cm.getColumnWidth(i);
\r
1038 var frac = (aw - cm.getTotalWidth())/width;
\r
1039 while (cols.length){
\r
1042 cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true);
\r
1045 if((tw = cm.getTotalWidth(false)) > aw){
\r
1046 var adjustCol = ac != vc ? omitColumn : extraCol;
\r
1047 cm.setColumnWidth(adjustCol, Math.max(1,
\r
1048 cm.getColumnWidth(adjustCol)- (tw-aw)), true);
\r
1051 if(preventRefresh !== true){
\r
1052 this.updateAllColumnWidths();
\r
1060 autoExpand : function(preventUpdate){
\r
1061 var g = this.grid, cm = this.cm;
\r
1062 if(!this.userResized && g.autoExpandColumn){
\r
1063 var tw = cm.getTotalWidth(false);
\r
1064 var aw = this.grid.getGridEl().getWidth(true)-this.scrollOffset;
\r
1066 var ci = cm.getIndexById(g.autoExpandColumn);
\r
1067 var currentWidth = cm.getColumnWidth(ci);
\r
1068 var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax);
\r
1069 if(cw != currentWidth){
\r
1070 cm.setColumnWidth(ci, cw, true);
\r
1071 if(preventUpdate !== true){
\r
1072 this.updateColumnWidth(ci, cw);
\r
1080 getColumnData : function(){
\r
1081 // build a map for all the columns
\r
1082 var cs = [], cm = this.cm, colCount = cm.getColumnCount();
\r
1083 for(var i = 0; i < colCount; i++){
\r
1084 var name = cm.getDataIndex(i);
\r
1086 name : (typeof name == 'undefined' ? this.ds.fields.get(i).name : name),
\r
1087 renderer : cm.getRenderer(i),
\r
1088 id : cm.getColumnId(i),
\r
1089 style : this.getColumnStyle(i)
\r
1096 renderRows : function(startRow, endRow){
\r
1097 // pull in all the crap needed to render rows
\r
1098 var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows;
\r
1099 var colCount = cm.getColumnCount();
\r
1101 if(ds.getCount() < 1){
\r
1105 var cs = this.getColumnData();
\r
1107 startRow = startRow || 0;
\r
1108 endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
\r
1110 // records to render
\r
1111 var rs = ds.getRange(startRow, endRow);
\r
1113 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
\r
1117 renderBody : function(){
\r
1118 var markup = this.renderRows();
\r
1119 return this.templates.body.apply({rows: markup});
\r
1123 refreshRow : function(record){
\r
1124 var ds = this.ds, index;
\r
1125 if(typeof record == 'number'){
\r
1127 record = ds.getAt(index);
\r
1129 index = ds.indexOf(record);
\r
1132 this.insertRows(ds, index, index, true);
\r
1133 this.getRow(index).rowIndex = index;
\r
1134 this.onRemove(ds, record, index+1, true);
\r
1135 this.fireEvent("rowupdated", this, index, record);
\r
1139 * Refreshs the grid UI
\r
1140 * @param {Boolean} headersToo (optional) True to also refresh the headers
\r
1142 refresh : function(headersToo){
\r
1143 this.fireEvent("beforerefresh", this);
\r
1144 this.grid.stopEditing(true);
\r
1146 var result = this.renderBody();
\r
1147 this.mainBody.update(result);
\r
1149 if(headersToo === true){
\r
1150 this.updateHeaders();
\r
1151 this.updateHeaderSortState();
\r
1153 this.processRows(0, true);
\r
1155 this.applyEmptyText();
\r
1156 this.fireEvent("refresh", this);
\r
1160 applyEmptyText : function(){
\r
1161 if(this.emptyText && !this.hasRows()){
\r
1162 this.mainBody.update('<div class="x-grid-empty">' + this.emptyText + '</div>');
\r
1167 updateHeaderSortState : function(){
\r
1168 var state = this.ds.getSortState();
\r
1172 if(!this.sortState || (this.sortState.field != state.field || this.sortState.direction != state.direction)){
\r
1173 this.grid.fireEvent('sortchange', this.grid, state);
\r
1175 this.sortState = state;
\r
1176 var sortColumn = this.cm.findColumnIndex(state.field);
\r
1177 if(sortColumn != -1){
\r
1178 var sortDir = state.direction;
\r
1179 this.updateSortIcon(sortColumn, sortDir);
\r
1184 destroy : function(){
\r
1186 Ext.menu.MenuMgr.unregister(this.colMenu);
\r
1187 this.colMenu.destroy();
\r
1188 delete this.colMenu;
\r
1191 Ext.menu.MenuMgr.unregister(this.hmenu);
\r
1192 this.hmenu.destroy();
\r
1193 delete this.hmenu;
\r
1195 if(this.grid.enableColumnMove){
\r
1196 var dds = Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
\r
1198 for(var dd in dds){
\r
1199 if(!dds[dd].config.isTarget && dds[dd].dragElId){
\r
1200 var elid = dds[dd].dragElId;
\r
1202 Ext.get(elid).remove();
\r
1203 } else if(dds[dd].config.isTarget){
\r
1204 dds[dd].proxyTop.remove();
\r
1205 dds[dd].proxyBottom.remove();
\r
1208 if(Ext.dd.DDM.locationCache[dd]){
\r
1209 delete Ext.dd.DDM.locationCache[dd];
\r
1212 delete Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
\r
1216 if(this.dragZone){
\r
1217 this.dragZone.unreg();
\r
1220 Ext.fly(this.innerHd).removeAllListeners();
\r
1221 Ext.removeNode(this.innerHd);
\r
1223 Ext.destroy(this.resizeMarker, this.resizeProxy, this.focusEl, this.mainBody,
\r
1224 this.scroller, this.mainHd, this.mainWrap, this.dragZone,
\r
1225 this.splitZone, this.columnDrag, this.columnDrop);
\r
1227 this.initData(null, null);
\r
1228 Ext.EventManager.removeResizeListener(this.onWindowResize, this);
\r
1229 this.purgeListeners();
\r
1233 onDenyColumnHide : function(){
\r
1238 render : function(){
\r
1239 if(this.autoFill){
\r
1240 var ct = this.grid.ownerCt;
\r
1241 if (ct && ct.getLayout()){
\r
1242 ct.on('afterlayout', function(){
\r
1243 this.fitColumns(true, true);
\r
1244 this.updateHeaders();
\r
1245 }, this, {single: true});
\r
1247 this.fitColumns(true, true);
\r
1249 }else if(this.forceFit){
\r
1250 this.fitColumns(true, false);
\r
1251 }else if(this.grid.autoExpandColumn){
\r
1252 this.autoExpand(true);
\r
1258 /* --------------------------------- Model Events and Handlers --------------------------------*/
\r
1260 initData : function(ds, cm){
\r
1262 this.ds.un("load", this.onLoad, this);
\r
1263 this.ds.un("datachanged", this.onDataChange, this);
\r
1264 this.ds.un("add", this.onAdd, this);
\r
1265 this.ds.un("remove", this.onRemove, this);
\r
1266 this.ds.un("update", this.onUpdate, this);
\r
1267 this.ds.un("clear", this.onClear, this);
\r
1270 ds.on("load", this.onLoad, this);
\r
1271 ds.on("datachanged", this.onDataChange, this);
\r
1272 ds.on("add", this.onAdd, this);
\r
1273 ds.on("remove", this.onRemove, this);
\r
1274 ds.on("update", this.onUpdate, this);
\r
1275 ds.on("clear", this.onClear, this);
\r
1280 this.cm.un("configchange", this.onColConfigChange, this);
\r
1281 this.cm.un("widthchange", this.onColWidthChange, this);
\r
1282 this.cm.un("headerchange", this.onHeaderChange, this);
\r
1283 this.cm.un("hiddenchange", this.onHiddenChange, this);
\r
1284 this.cm.un("columnmoved", this.onColumnMove, this);
\r
1285 this.cm.un("columnlockchange", this.onColumnLock, this);
\r
1288 delete this.lastViewWidth;
\r
1289 cm.on("configchange", this.onColConfigChange, this);
\r
1290 cm.on("widthchange", this.onColWidthChange, this);
\r
1291 cm.on("headerchange", this.onHeaderChange, this);
\r
1292 cm.on("hiddenchange", this.onHiddenChange, this);
\r
1293 cm.on("columnmoved", this.onColumnMove, this);
\r
1294 cm.on("columnlockchange", this.onColumnLock, this);
\r
1300 onDataChange : function(){
\r
1302 this.updateHeaderSortState();
\r
1303 this.syncFocusEl(0);
\r
1307 onClear : function(){
\r
1309 this.syncFocusEl(0);
\r
1313 onUpdate : function(ds, record){
\r
1314 this.refreshRow(record);
\r
1318 onAdd : function(ds, records, index){
\r
1319 this.insertRows(ds, index, index + (records.length-1));
\r
1323 onRemove : function(ds, record, index, isUpdate){
\r
1324 if(isUpdate !== true){
\r
1325 this.fireEvent("beforerowremoved", this, index, record);
\r
1327 this.removeRow(index);
\r
1328 if(isUpdate !== true){
\r
1329 this.processRows(index);
\r
1330 this.applyEmptyText();
\r
1331 this.fireEvent("rowremoved", this, index, record);
\r
1336 onLoad : function(){
\r
1337 this.scrollToTop();
\r
1341 onColWidthChange : function(cm, col, width){
\r
1342 this.updateColumnWidth(col, width);
\r
1346 onHeaderChange : function(cm, col, text){
\r
1347 this.updateHeaders();
\r
1351 onHiddenChange : function(cm, col, hidden){
\r
1352 this.updateColumnHidden(col, hidden);
\r
1356 onColumnMove : function(cm, oldIndex, newIndex){
\r
1357 this.indexMap = null;
\r
1358 var s = this.getScrollState();
\r
1359 this.refresh(true);
\r
1360 this.restoreScroll(s);
\r
1361 this.afterMove(newIndex);
\r
1365 onColConfigChange : function(){
\r
1366 delete this.lastViewWidth;
\r
1367 this.indexMap = null;
\r
1368 this.refresh(true);
\r
1371 /* -------------------- UI Events and Handlers ------------------------------ */
\r
1373 initUI : function(grid){
\r
1374 grid.on("headerclick", this.onHeaderClick, this);
\r
1378 initEvents : function(){
\r
1383 onHeaderClick : function(g, index){
\r
1384 if(this.headersDisabled || !this.cm.isSortable(index)){
\r
1387 g.stopEditing(true);
\r
1388 g.store.sort(this.cm.getDataIndex(index));
\r
1392 onRowOver : function(e, t){
\r
1394 if((row = this.findRowIndex(t)) !== false){
\r
1395 this.addRowClass(row, "x-grid3-row-over");
\r
1400 onRowOut : function(e, t){
\r
1402 if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){
\r
1403 this.removeRowClass(row, "x-grid3-row-over");
\r
1408 handleWheel : function(e){
\r
1409 e.stopPropagation();
\r
1413 onRowSelect : function(row){
\r
1414 this.addRowClass(row, "x-grid3-row-selected");
\r
1418 onRowDeselect : function(row){
\r
1419 this.removeRowClass(row, "x-grid3-row-selected");
\r
1423 onCellSelect : function(row, col){
\r
1424 var cell = this.getCell(row, col);
\r
1426 this.fly(cell).addClass("x-grid3-cell-selected");
\r
1431 onCellDeselect : function(row, col){
\r
1432 var cell = this.getCell(row, col);
\r
1434 this.fly(cell).removeClass("x-grid3-cell-selected");
\r
1439 onColumnSplitterMoved : function(i, w){
\r
1440 this.userResized = true;
\r
1441 var cm = this.grid.colModel;
\r
1442 cm.setColumnWidth(i, w, true);
\r
1444 if(this.forceFit){
\r
1445 this.fitColumns(true, false, i);
\r
1446 this.updateAllColumnWidths();
\r
1448 this.updateColumnWidth(i, w);
\r
1449 this.syncHeaderScroll();
\r
1452 this.grid.fireEvent("columnresize", i, w);
\r
1456 handleHdMenuClick : function(item){
\r
1457 var index = this.hdCtxIndex;
\r
1458 var cm = this.cm, ds = this.ds;
\r
1461 ds.sort(cm.getDataIndex(index), "ASC");
\r
1464 ds.sort(cm.getDataIndex(index), "DESC");
\r
1467 index = cm.getIndexById(item.id.substr(4));
\r
1469 if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){
\r
1470 this.onDenyColumnHide();
\r
1473 cm.setHidden(index, item.checked);
\r
1480 isHideableColumn : function(c){
\r
1481 return !c.hidden && !c.fixed;
\r
1485 beforeColMenuShow : function(){
\r
1486 var cm = this.cm, colCount = cm.getColumnCount();
\r
1487 this.colMenu.removeAll();
\r
1488 for(var i = 0; i < colCount; i++){
\r
1489 if(cm.config[i].fixed !== true && cm.config[i].hideable !== false){
\r
1490 this.colMenu.add(new Ext.menu.CheckItem({
\r
1491 id: "col-"+cm.getColumnId(i),
\r
1492 text: cm.getColumnHeader(i),
\r
1493 checked: !cm.isHidden(i),
\r
1494 hideOnClick:false,
\r
1495 disabled: cm.config[i].hideable === false
\r
1502 handleHdDown : function(e, t){
\r
1503 if(Ext.fly(t).hasClass('x-grid3-hd-btn')){
\r
1505 var hd = this.findHeaderCell(t);
\r
1506 Ext.fly(hd).addClass('x-grid3-hd-menu-open');
\r
1507 var index = this.getCellIndex(hd);
\r
1508 this.hdCtxIndex = index;
\r
1509 var ms = this.hmenu.items, cm = this.cm;
\r
1510 ms.get("asc").setDisabled(!cm.isSortable(index));
\r
1511 ms.get("desc").setDisabled(!cm.isSortable(index));
\r
1512 this.hmenu.on("hide", function(){
\r
1513 Ext.fly(hd).removeClass('x-grid3-hd-menu-open');
\r
1514 }, this, {single:true});
\r
1515 this.hmenu.show(t, "tl-bl?");
\r
1520 handleHdOver : function(e, t){
\r
1521 var hd = this.findHeaderCell(t);
\r
1522 if(hd && !this.headersDisabled){
\r
1523 this.activeHd = hd;
\r
1524 this.activeHdIndex = this.getCellIndex(hd);
\r
1525 var fly = this.fly(hd);
\r
1526 this.activeHdRegion = fly.getRegion();
\r
1527 if(!this.cm.isMenuDisabled(this.activeHdIndex)){
\r
1528 fly.addClass("x-grid3-hd-over");
\r
1529 this.activeHdBtn = fly.child('.x-grid3-hd-btn');
\r
1530 if(this.activeHdBtn){
\r
1531 this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px';
\r
1538 handleHdMove : function(e, t){
\r
1539 if(this.activeHd && !this.headersDisabled){
\r
1540 var hw = this.splitHandleWidth || 5;
\r
1541 var r = this.activeHdRegion;
\r
1542 var x = e.getPageX();
\r
1543 var ss = this.activeHd.style;
\r
1544 if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){
\r
1545 ss.cursor = Ext.isAir ? 'move' : Ext.isSafari ? 'e-resize' : 'col-resize'; // col-resize not always supported
\r
1546 }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){
\r
1547 ss.cursor = Ext.isAir ? 'move' : Ext.isSafari ? 'w-resize' : 'col-resize';
\r
1555 handleHdOut : function(e, t){
\r
1556 var hd = this.findHeaderCell(t);
\r
1557 if(hd && (!Ext.isIE || !e.within(hd, true))){
\r
1558 this.activeHd = null;
\r
1559 this.fly(hd).removeClass("x-grid3-hd-over");
\r
1560 hd.style.cursor = '';
\r
1565 hasRows : function(){
\r
1566 var fc = this.mainBody.dom.firstChild;
\r
1567 return fc && fc.className != 'x-grid-empty';
\r
1571 bind : function(d, c){
\r
1572 this.initData(d, c);
\r
1578 // This is a support class used internally by the Grid components
\r
1579 Ext.grid.GridView.SplitDragZone = function(grid, hd){
\r
1581 this.view = grid.getView();
\r
1582 this.marker = this.view.resizeMarker;
\r
1583 this.proxy = this.view.resizeProxy;
\r
1584 Ext.grid.GridView.SplitDragZone.superclass.constructor.call(this, hd,
\r
1585 "gridSplitters" + this.grid.getGridEl().id, {
\r
1586 dragElId : Ext.id(this.proxy.dom), resizeFrame:false
\r
1588 this.scroll = false;
\r
1589 this.hw = this.view.splitHandleWidth || 5;
\r
1591 Ext.extend(Ext.grid.GridView.SplitDragZone, Ext.dd.DDProxy, {
\r
1593 b4StartDrag : function(x, y){
\r
1594 this.view.headersDisabled = true;
\r
1595 var h = this.view.mainWrap.getHeight();
\r
1596 this.marker.setHeight(h);
\r
1597 this.marker.show();
\r
1598 this.marker.alignTo(this.view.getHeaderCell(this.cellIndex), 'tl-tl', [-2, 0]);
\r
1599 this.proxy.setHeight(h);
\r
1600 var w = this.cm.getColumnWidth(this.cellIndex);
\r
1601 var minw = Math.max(w-this.grid.minColumnWidth, 0);
\r
1602 this.resetConstraints();
\r
1603 this.setXConstraint(minw, 1000);
\r
1604 this.setYConstraint(0, 0);
\r
1605 this.minX = x - minw;
\r
1606 this.maxX = x + 1000;
\r
1607 this.startPos = x;
\r
1608 Ext.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
\r
1612 handleMouseDown : function(e){
\r
1613 var t = this.view.findHeaderCell(e.getTarget());
\r
1615 var xy = this.view.fly(t).getXY(), x = xy[0], y = xy[1];
\r
1616 var exy = e.getXY(), ex = exy[0], ey = exy[1];
\r
1617 var w = t.offsetWidth, adjust = false;
\r
1618 if((ex - x) <= this.hw){
\r
1620 }else if((x+w) - ex <= this.hw){
\r
1623 if(adjust !== false){
\r
1624 this.cm = this.grid.colModel;
\r
1625 var ci = this.view.getCellIndex(t);
\r
1627 if (ci + adjust < 0) {
\r
1630 while(this.cm.isHidden(ci+adjust)){
\r
1632 if(ci+adjust < 0){
\r
1637 this.cellIndex = ci+adjust;
\r
1638 this.split = t.dom;
\r
1639 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
\r
1640 Ext.grid.GridView.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
\r
1642 }else if(this.view.columnDrag){
\r
1643 this.view.columnDrag.callHandleMouseDown(e);
\r
1648 endDrag : function(e){
\r
1649 this.marker.hide();
\r
1650 var v = this.view;
\r
1651 var endX = Math.max(this.minX, e.getPageX());
\r
1652 var diff = endX - this.startPos;
\r
1653 v.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
\r
1654 setTimeout(function(){
\r
1655 v.headersDisabled = false;
\r
1659 autoOffset : function(){
\r
1660 this.setDelta(0,0);
\r