X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/6a7e4474cba9d8be4b2ec445e10f1691f7277c50..0494b8d9b9bb03ab6c22b34dae81261e3cd7e3e6:/src/widgets/grid/GridView.js?ds=sidebyside diff --git a/src/widgets/grid/GridView.js b/src/widgets/grid/GridView.js index eabb4876..0baab376 100644 --- a/src/widgets/grid/GridView.js +++ b/src/widgets/grid/GridView.js @@ -1,8 +1,8 @@ /*! - * Ext JS Library 3.2.0 - * Copyright(c) 2006-2010 Ext JS, Inc. - * licensing@extjs.com - * http://www.extjs.com/license + * Ext JS Library 3.3.1 + * Copyright(c) 2006-2010 Sencha Inc. + * licensing@sencha.com + * http://www.sencha.com/license */ /** * @class Ext.grid.GridView @@ -117,11 +117,14 @@ viewConfig: { /** * @cfg {Boolean} forceFit - * Defaults to false. Specify true to have the column widths re-proportioned - * at all times. The {@link Ext.grid.Column#width initially configured width} of each + *

Defaults to false. Specify true to have the column widths re-proportioned + * at all times.

+ *

The {@link Ext.grid.Column#width initially configured width} of each * column will be adjusted to fit the grid width and prevent horizontal scrolling. If columns are * later resized (manually or programmatically), the other columns in the grid will be resized - * to fit the grid width. See {@link #autoFill} also. + * to fit the grid width.

+ *

Columns which are configured with fixed: true are omitted from being resized.

+ *

See {@link #autoFill}.

*/ forceFit : false, @@ -166,12 +169,18 @@ viewConfig: { borderWidth : 2, tdClass : 'x-grid3-cell', hdCls : 'x-grid3-hd', + + + /** + * @cfg {Boolean} markDirty True to show the dirty cell indicator when a cell has been modified. Defaults to true. + */ markDirty : true, /** * @cfg {Number} cellSelectorDepth The number of levels to search for cells in event delegation (defaults to 4) */ cellSelectorDepth : 4, + /** * @cfg {Number} rowSelectorDepth The number of levels to search for rows in event delegation (defaults to 10) */ @@ -186,6 +195,7 @@ viewConfig: { * @cfg {String} cellSelector The selector used to find cells internally (defaults to 'td.x-grid3-cell') */ cellSelector : 'td.x-grid3-cell', + /** * @cfg {String} rowSelector The selector used to find rows internally (defaults to 'div.x-grid3-row') */ @@ -200,9 +210,20 @@ viewConfig: { firstRowCls: 'x-grid3-row-first', lastRowCls: 'x-grid3-row-last', rowClsRe: /(?:^|\s+)x-grid3-row-(first|last|alt)(?:\s+|$)/g, + + /** + * @cfg {String} headerMenuOpenCls The CSS class to add to the header cell when its menu is visible. Defaults to 'x-grid3-hd-menu-open' + */ + headerMenuOpenCls: 'x-grid3-hd-menu-open', + + /** + * @cfg {String} rowOverCls The CSS class added to each row when it is hovered over. Defaults to 'x-grid3-row-over' + */ + rowOverCls: 'x-grid3-row-over', - constructor : function(config){ + constructor : function(config) { Ext.apply(this, config); + // These events are only used internally by the grid components this.addEvents( /** @@ -213,6 +234,7 @@ viewConfig: { * @param {Ext.data.Record} record The Record to be removed */ 'beforerowremoved', + /** * @event beforerowsinserted * Internal UI Event. Fired before rows are inserted. @@ -221,12 +243,14 @@ viewConfig: { * @param {Number} lastRow The index of the last row to be inserted. */ 'beforerowsinserted', + /** * @event beforerefresh * Internal UI Event. Fired before the view is refreshed. * @param {Ext.grid.GridView} view */ 'beforerefresh', + /** * @event rowremoved * Internal UI Event. Fired after a row is removed. @@ -235,6 +259,7 @@ viewConfig: { * @param {Ext.data.Record} record The Record that was removed */ 'rowremoved', + /** * @event rowsinserted * Internal UI Event. Fired after rows are inserted. @@ -243,6 +268,7 @@ viewConfig: { * @param {Number} lastRow The index of the last row inserted. */ 'rowsinserted', + /** * @event rowupdated * Internal UI Event. Fired after a row has been updated. @@ -251,6 +277,7 @@ viewConfig: { * @param {Ext.data.record} record The Record backing the row updated. */ 'rowupdated', + /** * @event refresh * Internal UI Event. Fired after the GridView's body has been refreshed. @@ -258,79 +285,132 @@ viewConfig: { */ 'refresh' ); + Ext.grid.GridView.superclass.constructor.call(this); }, /* -------------------------------- UI Specific ----------------------------- */ - - // private - initTemplates : function(){ - var ts = this.templates || {}; - if(!ts.master){ - ts.master = new Ext.Template( - '
', - '
', - '
{header}
', - '
{body}
', + + /** + * The master template to use when rendering the GridView. Has a default template + * @property Ext.Template + * @type masterTpl + */ + masterTpl: new Ext.Template( + '
', + '
', + '
', + '
', + '
{header}
', '
', - '
 
', - '
 
', - '
' - ); - } - - if(!ts.header){ - ts.header = new Ext.Template( - '', - '{cells}', + '
', + '', + '
', + '
{body}
', + '', + '
', + '', + '
 
', + '
 
', + '' + ), + + /** + * The template to use when rendering headers. Has a default template + * @property headerTpl + * @type Ext.Template + */ + headerTpl: new Ext.Template( + '
', + '', + '{cells}', + '', + '
' + ), + + /** + * The template to use when rendering the body. Has a default template + * @property bodyTpl + * @type Ext.Template + */ + bodyTpl: new Ext.Template('{rows}'), + + /** + * The template to use to render each cell. Has a default template + * @property cellTpl + * @type Ext.Template + */ + cellTpl: new Ext.Template( + '', + '
{value}
', + '' + ), + + /** + * @private + * Provides default templates if they are not given for this particular instance. Most of the templates are defined on + * the prototype, the ones defined inside this function are done so because they are based on Grid or GridView configuration + */ + initTemplates : function() { + var templates = this.templates || {}, + template, name, + + headerCellTpl = new Ext.Template( + '', + '
', + this.grid.enableHdMenu ? '' : '', + '{value}', + '', + '
', + '' + ), + + rowBodyText = [ + '', + '', + '
{body}
', + '', + '' + ].join(""), + + innerText = [ + '', + '', + '{cells}', + this.enableRowBody ? rowBodyText : '', + '', '
' - ); - } - - if(!ts.hcell){ - ts.hcell = new Ext.Template( - '
', this.grid.enableHdMenu ? '' : '', - '{value}', - '
' - ); - } - - if(!ts.body){ - ts.body = new Ext.Template('{rows}'); - } - - if(!ts.row){ - ts.row = new Ext.Template( - '
', - '{cells}', - (this.enableRowBody ? '' : ''), - '
{body}
' - ); - } - - if(!ts.cell){ - ts.cell = new Ext.Template( - '', - '
{value}
', - '' - ); - } + ].join(""); + + Ext.applyIf(templates, { + hcell : headerCellTpl, + cell : this.cellTpl, + body : this.bodyTpl, + header : this.headerTpl, + master : this.masterTpl, + row : new Ext.Template('
' + innerText + '
'), + rowInner: new Ext.Template(innerText) + }); - for(var k in ts){ - var t = ts[k]; - if(t && Ext.isFunction(t.compile) && !t.compiled){ - t.disableFormats = true; - t.compile(); + for (name in templates) { + template = templates[name]; + + if (template && Ext.isFunction(template.compile) && !template.compiled) { + template.disableFormats = true; + template.compile(); } } - this.templates = ts; + this.templates = templates; this.colRe = new RegExp('x-grid3-td-([^\\s]+)', ''); }, - // private - fly : function(el){ - if(!this._flyweight){ + /** + * @private + * Each GridView has its own private flyweight, accessed through this method + */ + fly : function(el) { + if (!this._flyweight) { this._flyweight = new Ext.Element.Flyweight(document.body); } this._flyweight.dom = el; @@ -338,56 +418,62 @@ viewConfig: { }, // private - getEditorParent : function(){ + getEditorParent : function() { return this.scroller.dom; }, - // private - initElements : function(){ - var E = Ext.Element; - - var el = this.grid.getGridEl().dom.firstChild; - var cs = el.childNodes; - - this.el = new E(el); - - this.mainWrap = new E(cs[0]); - this.mainHd = new E(this.mainWrap.dom.firstChild); - - if(this.grid.hideHeaders){ - this.mainHd.setDisplayed(false); - } - - this.innerHd = this.mainHd.dom.firstChild; - this.scroller = new E(this.mainWrap.dom.childNodes[1]); - if(this.forceFit){ - this.scroller.setStyle('overflow-x', 'hidden'); - } + /** + * @private + * Finds and stores references to important elements + */ + initElements : function() { + var Element = Ext.Element, + el = Ext.get(this.grid.getGridEl().dom.firstChild), + mainWrap = new Element(el.child('div.x-grid3-viewport')), + mainHd = new Element(mainWrap.child('div.x-grid3-header')), + scroller = new Element(mainWrap.child('div.x-grid3-scroller')); + + if (this.grid.hideHeaders) { + mainHd.setDisplayed(false); + } + + if (this.forceFit) { + scroller.setStyle('overflow-x', 'hidden'); + } + /** * Read-only. The GridView's body Element which encapsulates all rows in the Grid. * This {@link Ext.Element Element} is only available after the GridPanel has been rendered. * @type Ext.Element * @property mainBody */ - this.mainBody = new E(this.scroller.dom.firstChild); - - this.focusEl = new E(this.scroller.dom.childNodes[1]); + + Ext.apply(this, { + el : el, + mainWrap: mainWrap, + scroller: scroller, + mainHd : mainHd, + innerHd : mainHd.child('div.x-grid3-header-inner').dom, + mainBody: new Element(Element.fly(scroller).child('div.x-grid3-body')), + focusEl : new Element(Element.fly(scroller).child('a')), + + resizeMarker: new Element(el.child('div.x-grid3-resize-marker')), + resizeProxy : new Element(el.child('div.x-grid3-resize-proxy')) + }); + this.focusEl.swallowEvent('click', true); - - this.resizeMarker = new E(cs[1]); - this.resizeProxy = new E(cs[2]); }, // private - getRows : function(){ + getRows : function() { return this.hasRows() ? this.mainBody.dom.childNodes : []; }, // finder methods, used with delegation // private - findCell : function(el){ - if(!el){ + findCell : function(el) { + if (!el) { return false; } return this.fly(el).findParent(this.cellSelector, this.cellSelectorDepth); @@ -399,27 +485,33 @@ viewConfig: { * @param {HTMLElement} el The target element * @return {Number} The column index, or false if the target element is not within a row of this GridView. */ - findCellIndex : function(el, requiredCls){ - var cell = this.findCell(el); - if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){ - return this.getCellIndex(cell); + findCellIndex : function(el, requiredCls) { + var cell = this.findCell(el), + hasCls; + + if (cell) { + hasCls = this.fly(cell).hasClass(requiredCls); + if (!requiredCls || hasCls) { + return this.getCellIndex(cell); + } } return false; }, // private - getCellIndex : function(el){ - if(el){ - var m = el.className.match(this.colRe); - if(m && m[1]){ - return this.cm.getIndexById(m[1]); + getCellIndex : function(el) { + if (el) { + var match = el.className.match(this.colRe); + + if (match && match[1]) { + return this.cm.getIndexById(match[1]); } } return false; }, // private - findHeaderCell : function(el){ + findHeaderCell : function(el) { var cell = this.findCell(el); return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null; }, @@ -434,22 +526,22 @@ viewConfig: { * @param {HTMLElement} el The target HTMLElement * @return {HTMLElement} The row element, or null if the target element is not within a row of this GridView. */ - findRow : function(el){ - if(!el){ + findRow : function(el) { + if (!el) { return false; } return this.fly(el).findParent(this.rowSelector, this.rowSelectorDepth); }, /** - *

Return the index of the grid row which contains the passed HTMLElement.

+ * Return the index of the grid row which contains the passed HTMLElement. * See also {@link #findCellIndex} * @param {HTMLElement} el The target HTMLElement * @return {Number} The row index, or false if the target element is not within a row of this GridView. */ - findRowIndex : function(el){ - var r = this.findRow(el); - return r ? r.rowIndex : false; + findRowIndex : function(el) { + var row = this.findRow(el); + return row ? row.rowIndex : false; }, /** @@ -457,10 +549,11 @@ viewConfig: { * @param {HTMLElement} el The target HTMLElement * @return {HTMLElement} The row body element, or null if the target element is not within a row body of this GridView. */ - findRowBody : function(el){ - if(!el){ + findRowBody : function(el) { + if (!el) { return false; } + return this.fly(el).findParent(this.rowBodySelector, this.rowBodySelectorDepth); }, @@ -471,7 +564,7 @@ viewConfig: { * @param {Number} index The row index * @return {HtmlElement} The div element. */ - getRow : function(row){ + getRow : function(row) { return this.getRows()[row]; }, @@ -481,8 +574,8 @@ viewConfig: { * @param {Number} col The column index of the cell. * @return {HtmlElement} The td at the specified coordinates. */ - getCell : function(row, col){ - return this.getRow(row).getElementsByTagName('td')[col]; + getCell : function(row, col) { + return Ext.fly(this.getRow(row)).query(this.cellSelector)[col]; }, /** @@ -490,22 +583,22 @@ viewConfig: { * @param {Number} index The column index * @return {HtmlElement} The td element. */ - getHeaderCell : function(index){ + getHeaderCell : function(index) { return this.mainHd.dom.getElementsByTagName('td')[index]; }, // manipulating elements // private - use getRowClass to apply custom row classes - addRowClass : function(row, cls){ - var r = this.getRow(row); - if(r){ - this.fly(r).addClass(cls); + addRowClass : function(rowId, cls) { + var row = this.getRow(rowId); + if (row) { + this.fly(row).addClass(cls); } }, // private - removeRowClass : function(row, cls){ + removeRowClass : function(row, cls) { var r = this.getRow(row); if(r){ this.fly(r).removeClass(cls); @@ -513,147 +606,177 @@ viewConfig: { }, // private - removeRow : function(row){ + removeRow : function(row) { Ext.removeNode(this.getRow(row)); this.syncFocusEl(row); }, // private - removeRows : function(firstRow, lastRow){ - var bd = this.mainBody.dom; - for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){ + removeRows : function(firstRow, lastRow) { + var bd = this.mainBody.dom, + rowIndex; + + for (rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){ Ext.removeNode(bd.childNodes[firstRow]); } + this.syncFocusEl(firstRow); }, - // scrolling stuff - + /* ----------------------------------- Scrolling functions -------------------------------------------*/ + // private - getScrollState : function(){ + getScrollState : function() { var sb = this.scroller.dom; - return {left: sb.scrollLeft, top: sb.scrollTop}; + + return { + left: sb.scrollLeft, + top : sb.scrollTop + }; }, // private - restoreScroll : function(state){ + restoreScroll : function(state) { var sb = this.scroller.dom; sb.scrollLeft = state.left; - sb.scrollTop = state.top; + sb.scrollTop = state.top; }, /** * Scrolls the grid to the top */ - scrollToTop : function(){ - this.scroller.dom.scrollTop = 0; - this.scroller.dom.scrollLeft = 0; + scrollToTop : function() { + var dom = this.scroller.dom; + + dom.scrollTop = 0; + dom.scrollLeft = 0; }, // private - syncScroll : function(){ + syncScroll : function() { this.syncHeaderScroll(); var mb = this.scroller.dom; this.grid.fireEvent('bodyscroll', mb.scrollLeft, mb.scrollTop); }, // private - syncHeaderScroll : function(){ - var mb = this.scroller.dom; - this.innerHd.scrollLeft = mb.scrollLeft; - this.innerHd.scrollLeft = mb.scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore) + syncHeaderScroll : function() { + var innerHd = this.innerHd, + scrollLeft = this.scroller.dom.scrollLeft; + + innerHd.scrollLeft = scrollLeft; + innerHd.scrollLeft = scrollLeft; // second time for IE (1/2 time first fails, other browsers ignore) }, - - // private - updateSortIcon : function(col, dir){ - var sc = this.sortClasses; - var hds = this.mainHd.select('td').removeClass(sc); - hds.item(col).addClass(sc[dir == 'DESC' ? 1 : 0]); + + /** + * @private + * Ensures the given column has the given icon class + */ + updateSortIcon : function(col, dir) { + var sortClasses = this.sortClasses, + sortClass = sortClasses[dir == "DESC" ? 1 : 0], + headers = this.mainHd.select('td').removeClass(sortClasses); + + headers.item(col).addClass(sortClass); }, - // private - updateAllColumnWidths : function(){ - var tw = this.getTotalWidth(), - clen = this.cm.getColumnCount(), - ws = [], - len, - i; - - for(i = 0; i < clen; i++){ - ws[i] = this.getColumnWidth(i); - } - - this.innerHd.firstChild.style.width = this.getOffsetWidth(); - this.innerHd.firstChild.firstChild.style.width = tw; - this.mainBody.dom.style.width = tw; - - for(i = 0; i < clen; i++){ - var hd = this.getHeaderCell(i); - hd.style.width = ws[i]; - } - - var ns = this.getRows(), row, trow; - for(i = 0, len = ns.length; i < len; i++){ - row = ns[i]; - row.style.width = tw; - if(row.firstChild){ - row.firstChild.style.width = tw; - trow = row.firstChild.rows[0]; - for (var j = 0; j < clen; j++) { - trow.childNodes[j].style.width = ws[j]; + /** + * @private + * Updates the size of every column and cell in the grid + */ + updateAllColumnWidths : function() { + var totalWidth = this.getTotalWidth(), + colCount = this.cm.getColumnCount(), + rows = this.getRows(), + rowCount = rows.length, + widths = [], + row, rowFirstChild, trow, i, j; + + for (i = 0; i < colCount; i++) { + widths[i] = this.getColumnWidth(i); + this.getHeaderCell(i).style.width = widths[i]; + } + + this.updateHeaderWidth(); + + for (i = 0; i < rowCount; i++) { + row = rows[i]; + row.style.width = totalWidth; + rowFirstChild = row.firstChild; + + if (rowFirstChild) { + rowFirstChild.style.width = totalWidth; + trow = rowFirstChild.rows[0]; + + for (j = 0; j < colCount; j++) { + trow.childNodes[j].style.width = widths[j]; } } } - - this.onAllColumnWidthsUpdated(ws, tw); + + this.onAllColumnWidthsUpdated(widths, totalWidth); }, - // private - updateColumnWidth : function(col, width){ - var w = this.getColumnWidth(col); - var tw = this.getTotalWidth(); - this.innerHd.firstChild.style.width = this.getOffsetWidth(); - this.innerHd.firstChild.firstChild.style.width = tw; - this.mainBody.dom.style.width = tw; - var hd = this.getHeaderCell(col); - hd.style.width = w; - - var ns = this.getRows(), row; - for(var i = 0, len = ns.length; i < len; i++){ - row = ns[i]; - row.style.width = tw; - if(row.firstChild){ - row.firstChild.style.width = tw; - row.firstChild.rows[0].childNodes[col].style.width = w; + /** + * @private + * Called after a column's width has been updated, this resizes all of the cells for that column in each row + * @param {Number} column The column index + */ + updateColumnWidth : function(column, width) { + var columnWidth = this.getColumnWidth(column), + totalWidth = this.getTotalWidth(), + headerCell = this.getHeaderCell(column), + nodes = this.getRows(), + nodeCount = nodes.length, + row, i, firstChild; + + this.updateHeaderWidth(); + headerCell.style.width = columnWidth; + + for (i = 0; i < nodeCount; i++) { + row = nodes[i]; + firstChild = row.firstChild; + + row.style.width = totalWidth; + if (firstChild) { + firstChild.style.width = totalWidth; + firstChild.rows[0].childNodes[column].style.width = columnWidth; } } - - this.onColumnWidthUpdated(col, w, tw); + + this.onColumnWidthUpdated(column, columnWidth, totalWidth); }, - - // private - updateColumnHidden : function(col, hidden){ - var tw = this.getTotalWidth(); - this.innerHd.firstChild.style.width = this.getOffsetWidth(); - this.innerHd.firstChild.firstChild.style.width = tw; - this.mainBody.dom.style.width = tw; - var display = hidden ? 'none' : ''; - - var hd = this.getHeaderCell(col); - hd.style.display = display; - - var ns = this.getRows(), row; - for(var i = 0, len = ns.length; i < len; i++){ - row = ns[i]; - row.style.width = tw; - if(row.firstChild){ - row.firstChild.style.width = tw; - row.firstChild.rows[0].childNodes[col].style.display = display; + + /** + * @private + * Sets the hidden status of a given column. + * @param {Number} col The column index + * @param {Boolean} hidden True to make the column hidden + */ + updateColumnHidden : function(col, hidden) { + var totalWidth = this.getTotalWidth(), + display = hidden ? 'none' : '', + headerCell = this.getHeaderCell(col), + nodes = this.getRows(), + nodeCount = nodes.length, + row, rowFirstChild, i; + + this.updateHeaderWidth(); + headerCell.style.display = display; + + for (i = 0; i < nodeCount; i++) { + row = nodes[i]; + row.style.width = totalWidth; + rowFirstChild = row.firstChild; + + if (rowFirstChild) { + rowFirstChild.style.width = totalWidth; + rowFirstChild.rows[0].childNodes[col].style.display = display; } } - - this.onColumnHiddenUpdated(col, hidden, tw); - delete this.lastViewWidth; // force recalc + + this.onColumnHiddenUpdated(col, hidden, totalWidth); + delete this.lastViewWidth; //recalc this.layout(); }, @@ -671,32 +794,32 @@ viewConfig: { * @return {String} A string containing the HTML for the rendered rows */ doRender : function(columns, records, store, startRow, colCount, stripe) { - var templates = this.templates, + var templates = this.templates, cellTemplate = templates.cell, - rowTemplate = templates.row, - last = colCount - 1; - - var tstyle = 'width:' + this.getTotalWidth() + ';'; - - // buffers - var rowBuffer = [], + rowTemplate = templates.row, + last = colCount - 1, + tstyle = 'width:' + this.getTotalWidth() + ';', + // buffers + rowBuffer = [], colBuffer = [], rowParams = {tstyle: tstyle}, - meta = {}, + meta = {}, + len = records.length, + alt, column, - record; + record, i, j, rowIndex; //build up each row's HTML - for (var j = 0, len = records.length; j < len; j++) { + for (j = 0; j < len; j++) { record = records[j]; colBuffer = []; - var rowIndex = j + startRow; + rowIndex = j + startRow; //build up each column's HTML - for (var i = 0; i < colCount; i++) { + for (i = 0; i < colCount; i++) { column = columns[i]; - + meta.id = column.id; meta.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : ''); meta.attr = meta.cellAttr = ''; @@ -707,16 +830,15 @@ viewConfig: { meta.value = ' '; } - if (this.markDirty && record.dirty && Ext.isDefined(record.modified[column.name])) { + if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') { meta.css += ' x-grid3-dirty-cell'; } colBuffer[colBuffer.length] = cellTemplate.apply(meta); } + alt = []; //set up row striping and row dirtiness CSS classes - var alt = []; - if (stripe && ((rowIndex + 1) % 2 === 0)) { alt[0] = 'x-grid3-row-alt'; } @@ -740,27 +862,31 @@ viewConfig: { return rowBuffer.join(''); }, - // private + /** + * @private + * Adds CSS classes and rowIndex to each row + * @param {Number} startRow The row to start from (defaults to 0) + */ processRows : function(startRow, skipStripe) { if (!this.ds || this.ds.getCount() < 1) { return; } - var rows = this.getRows(), - len = rows.length, - i, r; + var rows = this.getRows(), + length = rows.length, + row, i; skipStripe = skipStripe || !this.grid.stripeRows; startRow = startRow || 0; - for (i = 0; icolumn->row +// We must allow a return of false at any of these levels to cancel the event processing. +// Particularly allowing rowmousedown to be cancellable by prior handlers which need to prevent selection. if (row !== false) { - g.fireEvent('row' + name, g, row, e); - cell = this.findCellIndex(t); + cell = this.findCellIndex(target); if (cell !== false) { - g.fireEvent('cell' + name, g, row, cell, e); + col = grid.colModel.getColumnAt(cell); + if (grid.fireEvent('cell' + name, grid, row, cell, e) !== false) { + if (!col || (col.processEvent && (col.processEvent(name, e, grid, row, cell) !== false))) { + grid.fireEvent('row' + name, grid, row, e); + } + } } else { - body = this.findRowBody(t); - if (body) { - g.fireEvent('rowbody' + name, g, row, e); + if (grid.fireEvent('row' + name, grid, row, e) !== false) { + (body = this.findRowBody(target)) && grid.fireEvent('rowbody' + name, grid, row, e); } } } else { - g.fireEvent('container' + name, g, e); + grid.fireEvent('container' + name, grid, e); } } }, - // private - layout : function() { - if(!this.mainBody){ + /** + * @private + * Sizes the grid's header and body elements + */ + layout : function(initial) { + if (!this.mainBody) { return; // not rendered } - var g = this.grid; - var c = g.getGridEl(); - var csize = c.getSize(true); - var vw = csize.width; - if(!g.hideHeaders && (vw < 20 || csize.height < 20)){ // display: none? + var grid = this.grid, + gridEl = grid.getGridEl(), + gridSize = gridEl.getSize(true), + gridWidth = gridSize.width, + gridHeight = gridSize.height, + scroller = this.scroller, + scrollStyle, headerHeight, scrollHeight; + + if (gridWidth < 20 || gridHeight < 20) { return; } - - if(g.autoHeight){ - this.scroller.dom.style.overflow = 'visible'; - if(Ext.isWebKit){ - this.scroller.dom.style.position = 'static'; + + if (grid.autoHeight) { + scrollStyle = scroller.dom.style; + scrollStyle.overflow = 'visible'; + + if (Ext.isWebKit) { + scrollStyle.position = 'static'; } - }else{ - this.el.setSize(csize.width, csize.height); - - var hdHeight = this.mainHd.getHeight(); - var vh = csize.height - (hdHeight); - - this.scroller.setSize(vw, vh); - if(this.innerHd){ - this.innerHd.style.width = (vw)+'px'; + } else { + this.el.setSize(gridWidth, gridHeight); + + headerHeight = this.mainHd.getHeight(); + scrollHeight = gridHeight - headerHeight; + + scroller.setSize(gridWidth, scrollHeight); + + if (this.innerHd) { + this.innerHd.style.width = (gridWidth) + "px"; } } - if(this.forceFit){ - if(this.lastViewWidth != vw){ + + if (this.forceFit || (initial === true && this.autoFill)) { + if (this.lastViewWidth != gridWidth) { this.fitColumns(false, false); - this.lastViewWidth = vw; + this.lastViewWidth = gridWidth; } - }else { + } else { this.autoExpand(); this.syncHeaderScroll(); } - this.onLayout(vw, vh); + + this.onLayout(gridWidth, scrollHeight); }, // template functions for subclasses and plugins // these functions include precalculated values - onLayout : function(vw, vh){ + onLayout : function(vw, vh) { // do nothing }, - onColumnWidthUpdated : function(col, w, tw){ + onColumnWidthUpdated : function(col, w, tw) { //template method }, - onAllColumnWidthsUpdated : function(ws, tw){ + onAllColumnWidthsUpdated : function(ws, tw) { //template method }, - onColumnHiddenUpdated : function(col, hidden, tw){ + onColumnHiddenUpdated : function(col, hidden, tw) { // template method }, - updateColumnText : function(col, text){ + updateColumnText : function(col, text) { // template method }, - afterMove : function(colIndex){ + afterMove : function(colIndex) { // template method }, /* ----------------------------------- Core Specific -------------------------------------------*/ // private - init : function(grid){ + init : function(grid) { this.grid = grid; this.initTemplates(); @@ -983,7 +1137,7 @@ viewConfig: { // private getColumnId : function(index){ - return this.cm.getColumnId(index); + return this.cm.getColumnId(index); }, // private @@ -991,7 +1145,8 @@ viewConfig: { return (this.cm.getTotalWidth() + this.getScrollOffset()) + 'px'; }, - getScrollOffset: function(){ + // private + getScrollOffset: function() { return Ext.num(this.scrollOffset, Ext.getScrollBarWidth()); }, @@ -1002,61 +1157,98 @@ viewConfig: { * @return {String} Rendered header row */ renderHeaders : function() { - var cm = this.cm, - ts = this.templates, - ct = ts.hcell, - cb = [], - p = {}, - len = cm.getColumnCount(), - last = len - 1; - - for (var i = 0; i < len; i++) { - p.id = cm.getColumnId(i); - p.value = cm.getColumnHeader(i) || ''; - p.style = this.getColumnStyle(i, true); - p.tooltip = this.getColumnTooltip(i); - p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : ''); - - if (cm.config[i].align == 'right') { - p.istyle = 'padding-right:16px'; + var colModel = this.cm, + templates = this.templates, + headerTpl = templates.hcell, + properties = {}, + colCount = colModel.getColumnCount(), + last = colCount - 1, + cells = [], + i, cssCls; + + for (i = 0; i < colCount; i++) { + if (i == 0) { + cssCls = 'x-grid3-cell-first '; } else { - delete p.istyle; + cssCls = i == last ? 'x-grid3-cell-last ' : ''; } - cb[cb.length] = ct.apply(p); + + properties = { + id : colModel.getColumnId(i), + value : colModel.getColumnHeader(i) || '', + style : this.getColumnStyle(i, true), + css : cssCls, + tooltip: this.getColumnTooltip(i) + }; + + if (colModel.config[i].align == 'right') { + properties.istyle = 'padding-right: 16px;'; + } else { + delete properties.istyle; + } + + cells[i] = headerTpl.apply(properties); } - return ts.header.apply({cells: cb.join(''), tstyle:'width:'+this.getTotalWidth()+';'}); + + return templates.header.apply({ + cells : cells.join(""), + tstyle: String.format("width: {0};", this.getTotalWidth()) + }); }, - // private - getColumnTooltip : function(i){ - var tt = this.cm.getColumnTooltip(i); - if(tt){ - if(Ext.QuickTips.isEnabled()){ - return 'ext:qtip="'+tt+'"'; - }else{ - return 'title="'+tt+'"'; + /** + * @private + */ + getColumnTooltip : function(i) { + var tooltip = this.cm.getColumnTooltip(i); + if (tooltip) { + if (Ext.QuickTips.isEnabled()) { + return 'ext:qtip="' + tooltip + '"'; + } else { + return 'title="' + tooltip + '"'; } } + return ''; }, // private - beforeUpdate : function(){ + beforeUpdate : function() { this.grid.stopEditing(true); }, - // private - updateHeaders : function(){ + /** + * @private + * Re-renders the headers and ensures they are sized correctly + */ + updateHeaders : function() { this.innerHd.firstChild.innerHTML = this.renderHeaders(); - this.innerHd.firstChild.style.width = this.getOffsetWidth(); - this.innerHd.firstChild.firstChild.style.width = this.getTotalWidth(); + + this.updateHeaderWidth(false); + }, + + /** + * @private + * Ensures that the header is sized to the total width available to it + * @param {Boolean} updateMain True to update the mainBody's width also (defaults to true) + */ + updateHeaderWidth: function(updateMain) { + var innerHdChild = this.innerHd.firstChild, + totalWidth = this.getTotalWidth(); + + innerHdChild.style.width = this.getOffsetWidth(); + innerHdChild.firstChild.style.width = totalWidth; + + if (updateMain !== false) { + this.mainBody.dom.style.width = totalWidth; + } }, /** * Focuses the specified row. * @param {Number} row The row index */ - focusRow : function(row){ + focusRow : function(row) { this.focusCell(row, 0, false); }, @@ -1065,75 +1257,110 @@ viewConfig: { * @param {Number} row The row index * @param {Number} col The column index */ - focusCell : function(row, col, hscroll){ + focusCell : function(row, col, hscroll) { this.syncFocusEl(this.ensureVisible(row, col, hscroll)); - if(Ext.isGecko){ - this.focusEl.focus(); - }else{ - this.focusEl.focus.defer(1, this.focusEl); + + var focusEl = this.focusEl; + + if (Ext.isGecko) { + focusEl.focus(); + } else { + focusEl.focus.defer(1, focusEl); } }, - resolveCell : function(row, col, hscroll){ - if(!Ext.isNumber(row)){ + /** + * @private + * Finds the Elements corresponding to the given row and column indexes + */ + resolveCell : function(row, col, hscroll) { + if (!Ext.isNumber(row)) { row = row.rowIndex; } - if(!this.ds){ + + if (!this.ds) { return null; } - if(row < 0 || row >= this.ds.getCount()){ + + if (row < 0 || row >= this.ds.getCount()) { return null; } col = (col !== undefined ? col : 0); - var rowEl = this.getRow(row), - cm = this.cm, - colCount = cm.getColumnCount(), + var rowEl = this.getRow(row), + colModel = this.cm, + colCount = colModel.getColumnCount(), cellEl; - if(!(hscroll === false && col === 0)){ - while(col < colCount && cm.isHidden(col)){ + + if (!(hscroll === false && col === 0)) { + while (col < colCount && colModel.isHidden(col)) { col++; } + cellEl = this.getCell(row, col); } return {row: rowEl, cell: cellEl}; }, - getResolvedXY : function(resolved){ - if(!resolved){ + /** + * @private + * Returns the XY co-ordinates of a given row/cell resolution (see {@link #resolveCell}) + * @return {Array} X and Y coords + */ + getResolvedXY : function(resolved) { + if (!resolved) { return null; } - var s = this.scroller.dom, c = resolved.cell, r = resolved.row; - return c ? Ext.fly(c).getXY() : [this.el.getX(), Ext.fly(r).getY()]; + + var cell = resolved.cell, + row = resolved.row; + + if (cell) { + return Ext.fly(cell).getXY(); + } else { + return [this.el.getX(), Ext.fly(row).getY()]; + } }, - syncFocusEl : function(row, col, hscroll){ + /** + * @private + * Moves the focus element to the x and y co-ordinates of the given row and column + */ + syncFocusEl : function(row, col, hscroll) { var xy = row; - if(!Ext.isArray(xy)){ + + if (!Ext.isArray(xy)) { row = Math.min(row, Math.max(0, this.getRows().length-1)); + if (isNaN(row)) { return; } + xy = this.getResolvedXY(this.resolveCell(row, col, hscroll)); } - this.focusEl.setXY(xy||this.scroller.getXY()); + + this.focusEl.setXY(xy || this.scroller.getXY()); }, - ensureVisible : function(row, col, hscroll){ + /** + * @private + */ + ensureVisible : function(row, col, hscroll) { var resolved = this.resolveCell(row, col, hscroll); - if(!resolved || !resolved.row){ - return; + + if (!resolved || !resolved.row) { + return null; } - var rowEl = resolved.row, + var rowEl = resolved.row, cellEl = resolved.cell, c = this.scroller.dom, - ctop = 0, p = rowEl, + ctop = 0, stop = this.el.dom; - while(p && p != stop){ + while (p && p != stop) { ctop += p.offsetTop; p = p.offsetParent; } @@ -1146,24 +1373,25 @@ viewConfig: { sbot = stop + ch; - if(ctop < stop){ + if (ctop < stop) { c.scrollTop = ctop; - }else if(cbot > sbot){ + } else if(cbot > sbot) { c.scrollTop = cbot-ch; } - if(hscroll !== false){ - var cleft = parseInt(cellEl.offsetLeft, 10); - var cright = cleft + cellEl.offsetWidth; - - var sleft = parseInt(c.scrollLeft, 10); - var sright = sleft + c.clientWidth; - if(cleft < sleft){ + if (hscroll !== false) { + var cleft = parseInt(cellEl.offsetLeft, 10), + cright = cleft + cellEl.offsetWidth, + sleft = parseInt(c.scrollLeft, 10), + sright = sleft + c.clientWidth; + + if (cleft < sleft) { c.scrollLeft = cleft; - }else if(cright > sright){ + } else if(cright > sright) { c.scrollLeft = cright-c.clientWidth; } } + return this.getResolvedXY(resolved); }, @@ -1193,8 +1421,8 @@ viewConfig: { Ext.DomHelper.insertHtml('beforeEnd', this.mainBody.dom, html); } if (!isUpdate) { - this.fireEvent('rowsinserted', this, firstRow, lastRow); this.processRows(firstRow); + this.fireEvent('rowsinserted', this, firstRow, lastRow); } else if (firstRow === 0 || firstRow >= last) { //ensure first/last row is kept after an update. Ext.fly(this.getRow(firstRow)).addClass(firstRow === 0 ? this.firstRowCls : this.lastRowCls); @@ -1203,11 +1431,14 @@ viewConfig: { this.syncFocusEl(firstRow); }, - // private - deleteRows : function(dm, firstRow, lastRow){ - if(dm.getRowCount()<1){ + /** + * @private + * DEPRECATED - this doesn't appear to be called anywhere in the library, remove in 4.0. + */ + deleteRows : function(dm, firstRow, lastRow) { + if (dm.getRowCount() < 1) { this.refresh(); - }else{ + } else { this.fireEvent('beforerowsdeleted', this, firstRow, lastRow); this.removeRows(firstRow, lastRow); @@ -1217,155 +1448,226 @@ viewConfig: { } }, - // private - getColumnStyle : function(col, isHeader){ - var style = !isHeader ? (this.cm.config[col].css || '') : ''; - style += 'width:'+this.getColumnWidth(col)+';'; - if(this.cm.isHidden(col)){ - style += 'display:none;'; - } - var align = this.cm.config[col].align; - if(align){ - style += 'text-align:'+align+';'; - } + /** + * @private + * Builds a CSS string for the given column index + * @param {Number} colIndex The column index + * @param {Boolean} isHeader True if getting the style for the column's header + * @return {String} The CSS string + */ + getColumnStyle : function(colIndex, isHeader) { + var colModel = this.cm, + colConfig = colModel.config, + style = isHeader ? '' : colConfig[colIndex].css || '', + align = colConfig[colIndex].align; + + style += String.format("width: {0};", this.getColumnWidth(colIndex)); + + if (colModel.isHidden(colIndex)) { + style += 'display: none; '; + } + + if (align) { + style += String.format("text-align: {0};", align); + } + return style; }, - // private - getColumnWidth : function(col){ - var w = this.cm.getColumnWidth(col); - if(Ext.isNumber(w)){ - return (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2) ? w : (w - this.borderWidth > 0 ? w - this.borderWidth : 0)) + 'px'; + /** + * @private + * Returns the width of a given column minus its border width + * @return {Number} The column index + * @return {String|Number} The width in pixels + */ + getColumnWidth : function(column) { + var columnWidth = this.cm.getColumnWidth(column), + borderWidth = this.borderWidth; + + if (Ext.isNumber(columnWidth)) { + if (Ext.isBorderBox || (Ext.isWebKit && !Ext.isSafari2)) { + return columnWidth + "px"; + } else { + return Math.max(columnWidth - borderWidth, 0) + "px"; + } + } else { + return columnWidth; } - return w; }, - // private - getTotalWidth : function(){ - return this.cm.getTotalWidth()+'px'; + /** + * @private + * Returns the total width of all visible columns + * @return {String} + */ + getTotalWidth : function() { + return this.cm.getTotalWidth() + 'px'; }, - // private - fitColumns : function(preventRefresh, onlyExpand, omitColumn){ - var cm = this.cm, i; - var tw = cm.getTotalWidth(false); - var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset(); - - if(aw < 20){ // not initialized, so don't screw up the default widths - return; - } - var extra = aw - tw; - - if(extra === 0){ + /** + * @private + * Resizes each column to fit the available grid width. + * TODO: The second argument isn't even used, remove it in 4.0 + * @param {Boolean} preventRefresh True to prevent resizing of each row to the new column sizes (defaults to false) + * @param {null} onlyExpand NOT USED, will be removed in 4.0 + * @param {Number} omitColumn The index of a column to leave at its current width. Defaults to undefined + * @return {Boolean} True if the operation succeeded, false if not or undefined if the grid view is not yet initialized + */ + fitColumns : function(preventRefresh, onlyExpand, omitColumn) { + var grid = this.grid, + colModel = this.cm, + totalColWidth = colModel.getTotalWidth(false), + gridWidth = this.getGridInnerWidth(), + extraWidth = gridWidth - totalColWidth, + columns = [], + extraCol = 0, + width = 0, + colWidth, fraction, i; + + // not initialized, so don't screw up the default widths + if (gridWidth < 20 || extraWidth === 0) { return false; } - - var vc = cm.getColumnCount(true); - var ac = vc-(Ext.isNumber(omitColumn) ? 1 : 0); - if(ac === 0){ - ac = 1; + + var visibleColCount = colModel.getColumnCount(true), + totalColCount = colModel.getColumnCount(false), + adjCount = visibleColCount - (Ext.isNumber(omitColumn) ? 1 : 0); + + if (adjCount === 0) { + adjCount = 1; omitColumn = undefined; } - var colCount = cm.getColumnCount(); - var cols = []; - var extraCol = 0; - var width = 0; - var w; - for (i = 0; i < colCount; i++){ - if(!cm.isHidden(i) && !cm.isFixed(i) && i !== omitColumn){ - w = cm.getColumnWidth(i); - cols.push(i); - extraCol = i; - cols.push(w); - width += w; + + //FIXME: the algorithm used here is odd and potentially confusing. Includes this for loop and the while after it. + for (i = 0; i < totalColCount; i++) { + if (!colModel.isFixed(i) && i !== omitColumn) { + colWidth = colModel.getColumnWidth(i); + columns.push(i, colWidth); + + if (!colModel.isHidden(i)) { + extraCol = i; + width += colWidth; + } } } - var frac = (aw - cm.getTotalWidth())/width; - while (cols.length){ - w = cols.pop(); - i = cols.pop(); - cm.setColumnWidth(i, Math.max(this.grid.minColumnWidth, Math.floor(w + w*frac)), true); - } - - if((tw = cm.getTotalWidth(false)) > aw){ - var adjustCol = ac != vc ? omitColumn : extraCol; - cm.setColumnWidth(adjustCol, Math.max(1, - cm.getColumnWidth(adjustCol)- (tw-aw)), true); + + fraction = (gridWidth - colModel.getTotalWidth()) / width; + + while (columns.length) { + colWidth = columns.pop(); + i = columns.pop(); + + colModel.setColumnWidth(i, Math.max(grid.minColumnWidth, Math.floor(colWidth + colWidth * fraction)), true); + } + + //this has been changed above so remeasure now + totalColWidth = colModel.getTotalWidth(false); + + if (totalColWidth > gridWidth) { + var adjustCol = (adjCount == visibleColCount) ? extraCol : omitColumn, + newWidth = Math.max(1, colModel.getColumnWidth(adjustCol) - (totalColWidth - gridWidth)); + + colModel.setColumnWidth(adjustCol, newWidth, true); } - - if(preventRefresh !== true){ + + if (preventRefresh !== true) { this.updateAllColumnWidths(); } - - + return true; }, - // private - autoExpand : function(preventUpdate){ - var g = this.grid, cm = this.cm; - if(!this.userResized && g.autoExpandColumn){ - var tw = cm.getTotalWidth(false); - var aw = this.grid.getGridEl().getWidth(true)-this.getScrollOffset(); - if(tw != aw){ - var ci = cm.getIndexById(g.autoExpandColumn); - var currentWidth = cm.getColumnWidth(ci); - var cw = Math.min(Math.max(((aw-tw)+currentWidth), g.autoExpandMin), g.autoExpandMax); - if(cw != currentWidth){ - cm.setColumnWidth(ci, cw, true); - if(preventUpdate !== true){ - this.updateColumnWidth(ci, cw); + /** + * @private + * Resizes the configured autoExpandColumn to take the available width after the other columns have + * been accounted for + * @param {Boolean} preventUpdate True to prevent the resizing of all rows (defaults to false) + */ + autoExpand : function(preventUpdate) { + var grid = this.grid, + colModel = this.cm, + gridWidth = this.getGridInnerWidth(), + totalColumnWidth = colModel.getTotalWidth(false), + autoExpandColumn = grid.autoExpandColumn; + + if (!this.userResized && autoExpandColumn) { + if (gridWidth != totalColumnWidth) { + //if we are not already using all available width, resize the autoExpandColumn + var colIndex = colModel.getIndexById(autoExpandColumn), + currentWidth = colModel.getColumnWidth(colIndex), + desiredWidth = gridWidth - totalColumnWidth + currentWidth, + newWidth = Math.min(Math.max(desiredWidth, grid.autoExpandMin), grid.autoExpandMax); + + if (currentWidth != newWidth) { + colModel.setColumnWidth(colIndex, newWidth, true); + + if (preventUpdate !== true) { + this.updateColumnWidth(colIndex, newWidth); } } } } }, + + /** + * Returns the total internal width available to the grid, taking the scrollbar into account + * @return {Number} The total width + */ + getGridInnerWidth: function() { + return this.grid.getGridEl().getWidth(true) - this.getScrollOffset(); + }, /** * @private * Returns an array of column configurations - one for each column * @return {Array} Array of column config objects. This includes the column name, renderer, id style and renderer */ - getColumnData : function(){ - // build a map for all the columns - var cs = [], - cm = this.cm, - colCount = cm.getColumnCount(); - - for (var i = 0; i < colCount; i++) { - var name = cm.getDataIndex(i); - - cs[i] = { - name : (!Ext.isDefined(name) ? this.ds.fields.get(i).name : name), - renderer: cm.getRenderer(i), - scope : cm.getRendererScope(i), - id : cm.getColumnId(i), + getColumnData : function() { + var columns = [], + colModel = this.cm, + colCount = colModel.getColumnCount(), + fields = this.ds.fields, + i, name; + + for (i = 0; i < colCount; i++) { + name = colModel.getDataIndex(i); + + columns[i] = { + name : Ext.isDefined(name) ? name : (fields.get(i) ? fields.get(i).name : undefined), + renderer: colModel.getRenderer(i), + scope : colModel.getRendererScope(i), + id : colModel.getColumnId(i), style : this.getColumnStyle(i) }; } - - return cs; + + return columns; }, - // private - renderRows : function(startRow, endRow){ - // pull in all the crap needed to render rows - var g = this.grid, cm = g.colModel, ds = g.store, stripe = g.stripeRows; - var colCount = cm.getColumnCount(); - - if(ds.getCount() < 1){ + /** + * @private + * Renders rows between start and end indexes + * @param {Number} startRow Index of the first row to render + * @param {Number} endRow Index of the last row to render + */ + renderRows : function(startRow, endRow) { + var grid = this.grid, + store = grid.store, + stripe = grid.stripeRows, + colModel = grid.colModel, + colCount = colModel.getColumnCount(), + rowCount = store.getCount(), + records; + + if (rowCount < 1) { return ''; } - - var cs = this.getColumnData(); - + startRow = startRow || 0; - endRow = !Ext.isDefined(endRow) ? ds.getCount()-1 : endRow; - - // records to render - var rs = ds.getRange(startRow, endRow); - - return this.doRender(cs, rs, ds, startRow, colCount, stripe); + endRow = Ext.isDefined(endRow) ? endRow : rowCount - 1; + records = store.getRange(startRow, endRow); + + return this.doRender(this.getColumnData(), records, store, startRow, colCount, stripe); }, // private @@ -1374,38 +1676,96 @@ viewConfig: { return this.templates.body.apply({rows: markup}); }, - // private - refreshRow : function(record){ - var ds = this.ds, index; - if(Ext.isNumber(record)){ - index = record; - record = ds.getAt(index); - if(!record){ - return; + /** + * @private + * Refreshes a row by re-rendering it. Fires the rowupdated event when done + */ + refreshRow: function(record) { + var store = this.ds, + colCount = this.cm.getColumnCount(), + columns = this.getColumnData(), + last = colCount - 1, + cls = ['x-grid3-row'], + rowParams = { + tstyle: String.format("width: {0};", this.getTotalWidth()) + }, + colBuffer = [], + cellTpl = this.templates.cell, + rowIndex, row, column, meta, css, i; + + if (Ext.isNumber(record)) { + rowIndex = record; + record = store.getAt(rowIndex); + } else { + rowIndex = store.indexOf(record); + } + + //the record could not be found + if (!record || rowIndex < 0) { + return; + } + + //builds each column in this row + for (i = 0; i < colCount; i++) { + column = columns[i]; + + if (i == 0) { + css = 'x-grid3-cell-first'; + } else { + css = (i == last) ? 'x-grid3-cell-last ' : ''; } - }else{ - index = ds.indexOf(record); - if(index < 0){ - return; + + meta = { + id : column.id, + style : column.style, + css : css, + attr : "", + cellAttr: "" + }; + // Need to set this after, because we pass meta to the renderer + meta.value = column.renderer.call(column.scope, record.data[column.name], meta, record, rowIndex, i, store); + + if (Ext.isEmpty(meta.value)) { + meta.value = ' '; + } + + if (this.markDirty && record.dirty && typeof record.modified[column.name] != 'undefined') { + meta.css += ' x-grid3-dirty-cell'; } + + colBuffer[i] = cellTpl.apply(meta); + } + + row = this.getRow(rowIndex); + row.className = ''; + + if (this.grid.stripeRows && ((rowIndex + 1) % 2 === 0)) { + cls.push('x-grid3-row-alt'); + } + + if (this.getRowClass) { + rowParams.cols = colCount; + cls.push(this.getRowClass(record, rowIndex, rowParams, store)); } - this.insertRows(ds, index, index, true); - this.getRow(index).rowIndex = index; - this.onRemove(ds, record, index+1, true); - this.fireEvent('rowupdated', this, index, record); + + this.fly(row).addClass(cls).setStyle(rowParams.tstyle); + rowParams.cells = colBuffer.join(""); + row.innerHTML = this.templates.rowInner.apply(rowParams); + + this.fireEvent('rowupdated', this, rowIndex, record); }, /** * Refreshs the grid UI * @param {Boolean} headersToo (optional) True to also refresh the headers */ - refresh : function(headersToo){ + refresh : function(headersToo) { this.fireEvent('beforerefresh', this); this.grid.stopEditing(true); var result = this.renderBody(); this.mainBody.update(result).setWidth(this.getTotalWidth()); - if(headersToo === true){ + if (headersToo === true) { this.updateHeaders(); this.updateHeaderSortState(); } @@ -1419,8 +1779,8 @@ viewConfig: { * @private * Displays the configured emptyText if there are currently no rows to display */ - applyEmptyText : function(){ - if(this.emptyText && !this.hasRows()){ + applyEmptyText : function() { + if (this.emptyText && !this.hasRows()) { this.mainBody.update('
' + this.emptyText + '
'); } }, @@ -1430,7 +1790,7 @@ viewConfig: { * Adds sorting classes to the column headers based on the bound store's sortInfo. Fires the 'sortchange' event * if the sorting has changed since this function was last run. */ - updateHeaderSortState : function(){ + updateHeaderSortState : function() { var state = this.ds.getSortState(); if (!state) { return; @@ -1443,7 +1803,7 @@ viewConfig: { this.sortState = state; var sortColumn = this.cm.findColumnIndex(state.field); - if (sortColumn != -1){ + if (sortColumn != -1) { var sortDir = state.direction; this.updateSortIcon(sortColumn, sortDir); } @@ -1453,7 +1813,7 @@ viewConfig: { * @private * Removes any sorting indicator classes from the column headers */ - clearHeaderSortState : function(){ + clearHeaderSortState : function() { if (!this.sortState) { return; } @@ -1462,241 +1822,278 @@ viewConfig: { delete this.sortState; }, - // private - destroy : function(){ - if (this.scrollToTopTask && this.scrollToTopTask.cancel){ - this.scrollToTopTask.cancel(); - } - if(this.colMenu){ - Ext.menu.MenuMgr.unregister(this.colMenu); - this.colMenu.destroy(); - delete this.colMenu; - } - if(this.hmenu){ - Ext.menu.MenuMgr.unregister(this.hmenu); - this.hmenu.destroy(); - delete this.hmenu; - } - - this.initData(null, null); - this.purgeListeners(); - Ext.fly(this.innerHd).un("click", this.handleHdDown, this); - - if(this.grid.enableColumnMove){ + /** + * @private + * Destroys all objects associated with the GridView + */ + destroy : function() { + var me = this, + grid = me.grid, + gridEl = grid.getGridEl(), + dragZone = me.dragZone, + splitZone = me.splitZone, + columnDrag = me.columnDrag, + columnDrop = me.columnDrop, + scrollToTopTask = me.scrollToTopTask, + columnDragData, + columnDragProxy; + + if (scrollToTopTask && scrollToTopTask.cancel) { + scrollToTopTask.cancel(); + } + + Ext.destroyMembers(me, 'colMenu', 'hmenu'); + + me.initData(null, null); + me.purgeListeners(); + + Ext.fly(me.innerHd).un("click", me.handleHdDown, me); + + if (grid.enableColumnMove) { + columnDragData = columnDrag.dragData; + columnDragProxy = columnDrag.proxy; Ext.destroy( - this.columnDrag.el, - this.columnDrag.proxy.ghost, - this.columnDrag.proxy.el, - this.columnDrop.el, - this.columnDrop.proxyTop, - this.columnDrop.proxyBottom, - this.columnDrag.dragData.ddel, - this.columnDrag.dragData.header + columnDrag.el, + columnDragProxy.ghost, + columnDragProxy.el, + columnDrop.el, + columnDrop.proxyTop, + columnDrop.proxyBottom, + columnDragData.ddel, + columnDragData.header ); - if (this.columnDrag.proxy.anim) { - Ext.destroy(this.columnDrag.proxy.anim); + + if (columnDragProxy.anim) { + Ext.destroy(columnDragProxy.anim); } - delete this.columnDrag.proxy.ghost; - delete this.columnDrag.dragData.ddel; - delete this.columnDrag.dragData.header; - this.columnDrag.destroy(); - delete Ext.dd.DDM.locationCache[this.columnDrag.id]; - delete this.columnDrag._domRef; + + delete columnDragProxy.ghost; + delete columnDragData.ddel; + delete columnDragData.header; + columnDrag.destroy(); + + delete Ext.dd.DDM.locationCache[columnDrag.id]; + delete columnDrag._domRef; - delete this.columnDrop.proxyTop; - delete this.columnDrop.proxyBottom; - this.columnDrop.destroy(); - delete Ext.dd.DDM.locationCache["gridHeader" + this.grid.getGridEl().id]; - delete this.columnDrop._domRef; - delete Ext.dd.DDM.ids[this.columnDrop.ddGroup]; + delete columnDrop.proxyTop; + delete columnDrop.proxyBottom; + columnDrop.destroy(); + delete Ext.dd.DDM.locationCache["gridHeader" + gridEl.id]; + delete columnDrop._domRef; + delete Ext.dd.DDM.ids[columnDrop.ddGroup]; } - if (this.splitZone){ // enableColumnResize - this.splitZone.destroy(); - delete this.splitZone._domRef; - delete Ext.dd.DDM.ids["gridSplitters" + this.grid.getGridEl().id]; + if (splitZone) { // enableColumnResize + splitZone.destroy(); + delete splitZone._domRef; + delete Ext.dd.DDM.ids["gridSplitters" + gridEl.id]; } - Ext.fly(this.innerHd).removeAllListeners(); - Ext.removeNode(this.innerHd); - delete this.innerHd; + Ext.fly(me.innerHd).removeAllListeners(); + Ext.removeNode(me.innerHd); + delete me.innerHd; Ext.destroy( - this.el, - this.mainWrap, - this.mainHd, - this.scroller, - this.mainBody, - this.focusEl, - this.resizeMarker, - this.resizeProxy, - this.activeHdBtn, - this.dragZone, - this.splitZone, - this._flyweight + me.el, + me.mainWrap, + me.mainHd, + me.scroller, + me.mainBody, + me.focusEl, + me.resizeMarker, + me.resizeProxy, + me.activeHdBtn, + me._flyweight, + dragZone, + splitZone ); - delete this.grid.container; + delete grid.container; - if(this.dragZone){ - this.dragZone.destroy(); + if (dragZone) { + dragZone.destroy(); } Ext.dd.DDM.currentTarget = null; - delete Ext.dd.DDM.locationCache[this.grid.getGridEl().id]; + delete Ext.dd.DDM.locationCache[gridEl.id]; - Ext.EventManager.removeResizeListener(this.onWindowResize, this); + Ext.EventManager.removeResizeListener(me.onWindowResize, me); }, // private - onDenyColumnHide : function(){ + onDenyColumnHide : function() { }, // private - render : function(){ - if(this.autoFill){ + render : function() { + if (this.autoFill) { var ct = this.grid.ownerCt; - if (ct && ct.getLayout()){ - ct.on('afterlayout', function(){ + + if (ct && ct.getLayout()) { + ct.on('afterlayout', function() { this.fitColumns(true, true); this.updateHeaders(); + this.updateHeaderSortState(); }, this, {single: true}); - }else{ - this.fitColumns(true, true); } - }else if(this.forceFit){ + } else if (this.forceFit) { this.fitColumns(true, false); - }else if(this.grid.autoExpandColumn){ + } else if (this.grid.autoExpandColumn) { this.autoExpand(true); } - - this.renderUI(); + + this.grid.getGridEl().dom.innerHTML = this.renderUI(); + + this.afterRenderUI(); }, /* --------------------------------- Model Events and Handlers --------------------------------*/ - // private - initData : function(ds, cm){ - if(this.ds){ - this.ds.un('load', this.onLoad, this); - this.ds.un('datachanged', this.onDataChange, this); - this.ds.un('add', this.onAdd, this); - this.ds.un('remove', this.onRemove, this); - this.ds.un('update', this.onUpdate, this); - this.ds.un('clear', this.onClear, this); - if(this.ds !== ds && this.ds.autoDestroy){ - this.ds.destroy(); + + /** + * @private + * Binds a new Store and ColumnModel to this GridView. Removes any listeners from the old objects (if present) + * and adds listeners to the new ones + * @param {Ext.data.Store} newStore The new Store instance + * @param {Ext.grid.ColumnModel} newColModel The new ColumnModel instance + */ + initData : function(newStore, newColModel) { + var me = this; + + if (me.ds) { + var oldStore = me.ds; + + oldStore.un('add', me.onAdd, me); + oldStore.un('load', me.onLoad, me); + oldStore.un('clear', me.onClear, me); + oldStore.un('remove', me.onRemove, me); + oldStore.un('update', me.onUpdate, me); + oldStore.un('datachanged', me.onDataChange, me); + + if (oldStore !== newStore && oldStore.autoDestroy) { + oldStore.destroy(); } } - if(ds){ - ds.on({ - scope: this, - load: this.onLoad, - datachanged: this.onDataChange, - add: this.onAdd, - remove: this.onRemove, - update: this.onUpdate, - clear: this.onClear + + if (newStore) { + newStore.on({ + scope : me, + load : me.onLoad, + add : me.onAdd, + remove : me.onRemove, + update : me.onUpdate, + clear : me.onClear, + datachanged: me.onDataChange }); } - this.ds = ds; - - if(this.cm){ - this.cm.un('configchange', this.onColConfigChange, this); - this.cm.un('widthchange', this.onColWidthChange, this); - this.cm.un('headerchange', this.onHeaderChange, this); - this.cm.un('hiddenchange', this.onHiddenChange, this); - this.cm.un('columnmoved', this.onColumnMove, this); - } - if(cm){ - delete this.lastViewWidth; - cm.on({ - scope: this, - configchange: this.onColConfigChange, - widthchange: this.onColWidthChange, - headerchange: this.onHeaderChange, - hiddenchange: this.onHiddenChange, - columnmoved: this.onColumnMove + + if (me.cm) { + var oldColModel = me.cm; + + oldColModel.un('configchange', me.onColConfigChange, me); + oldColModel.un('widthchange', me.onColWidthChange, me); + oldColModel.un('headerchange', me.onHeaderChange, me); + oldColModel.un('hiddenchange', me.onHiddenChange, me); + oldColModel.un('columnmoved', me.onColumnMove, me); + } + + if (newColModel) { + delete me.lastViewWidth; + + newColModel.on({ + scope : me, + configchange: me.onColConfigChange, + widthchange : me.onColWidthChange, + headerchange: me.onHeaderChange, + hiddenchange: me.onHiddenChange, + columnmoved : me.onColumnMove }); } - this.cm = cm; + + me.ds = newStore; + me.cm = newColModel; }, // private onDataChange : function(){ - this.refresh(); + this.refresh(true); this.updateHeaderSortState(); this.syncFocusEl(0); }, // private - onClear : function(){ + onClear : function() { this.refresh(); this.syncFocusEl(0); }, // private - onUpdate : function(ds, record){ + onUpdate : function(store, record) { this.refreshRow(record); }, // private - onAdd : function(ds, records, index){ - this.insertRows(ds, index, index + (records.length-1)); + onAdd : function(store, records, index) { + this.insertRows(store, index, index + (records.length-1)); }, // private - onRemove : function(ds, record, index, isUpdate){ - if(isUpdate !== true){ + onRemove : function(store, record, index, isUpdate) { + if (isUpdate !== true) { this.fireEvent('beforerowremoved', this, index, record); } + this.removeRow(index); - if(isUpdate !== true){ + + if (isUpdate !== true) { this.processRows(index); this.applyEmptyText(); this.fireEvent('rowremoved', this, index, record); } }, - // private - onLoad : function(){ - if (Ext.isGecko){ + /** + * @private + * Called when a store is loaded, scrolls to the top row + */ + onLoad : function() { + if (Ext.isGecko) { if (!this.scrollToTopTask) { this.scrollToTopTask = new Ext.util.DelayedTask(this.scrollToTop, this); } this.scrollToTopTask.delay(1); - }else{ + } else { this.scrollToTop(); } }, // private - onColWidthChange : function(cm, col, width){ + onColWidthChange : function(cm, col, width) { this.updateColumnWidth(col, width); }, // private - onHeaderChange : function(cm, col, text){ + onHeaderChange : function(cm, col, text) { this.updateHeaders(); }, // private - onHiddenChange : function(cm, col, hidden){ + onHiddenChange : function(cm, col, hidden) { this.updateColumnHidden(col, hidden); }, // private - onColumnMove : function(cm, oldIndex, newIndex){ + onColumnMove : function(cm, oldIndex, newIndex) { this.indexMap = null; - var s = this.getScrollState(); this.refresh(true); - this.restoreScroll(s); + this.restoreScroll(this.getScrollState()); + this.afterMove(newIndex); this.grid.fireEvent('columnmove', oldIndex, newIndex); }, // private - onColConfigChange : function(){ + onColConfigChange : function() { delete this.lastViewWidth; this.indexMap = null; this.refresh(true); @@ -1704,209 +2101,318 @@ viewConfig: { /* -------------------- UI Events and Handlers ------------------------------ */ // private - initUI : function(grid){ + initUI : function(grid) { grid.on('headerclick', this.onHeaderClick, this); }, // private - initEvents : function(){ - }, + initEvents : Ext.emptyFn, // private - onHeaderClick : function(g, index){ - if(this.headersDisabled || !this.cm.isSortable(index)){ + onHeaderClick : function(g, index) { + if (this.headersDisabled || !this.cm.isSortable(index)) { return; } g.stopEditing(true); g.store.sort(this.cm.getDataIndex(index)); }, - // private - onRowOver : function(e, t){ - var row; - if((row = this.findRowIndex(t)) !== false){ - this.addRowClass(row, 'x-grid3-row-over'); + /** + * @private + * Adds the hover class to a row when hovered over + */ + onRowOver : function(e, target) { + var row = this.findRowIndex(target); + + if (row !== false) { + this.addRowClass(row, this.rowOverCls); } }, - // private - onRowOut : function(e, t){ - var row; - if((row = this.findRowIndex(t)) !== false && !e.within(this.getRow(row), true)){ - this.removeRowClass(row, 'x-grid3-row-over'); + /** + * @private + * Removes the hover class from a row on mouseout + */ + onRowOut : function(e, target) { + var row = this.findRowIndex(target); + + if (row !== false && !e.within(this.getRow(row), true)) { + this.removeRowClass(row, this.rowOverCls); } }, // private - handleWheel : function(e){ - e.stopPropagation(); - }, - - // private - onRowSelect : function(row){ + onRowSelect : function(row) { this.addRowClass(row, this.selectedRowClass); }, // private - onRowDeselect : function(row){ + onRowDeselect : function(row) { this.removeRowClass(row, this.selectedRowClass); }, // private - onCellSelect : function(row, col){ + onCellSelect : function(row, col) { var cell = this.getCell(row, col); - if(cell){ + if (cell) { this.fly(cell).addClass('x-grid3-cell-selected'); } }, // private - onCellDeselect : function(row, col){ + onCellDeselect : function(row, col) { var cell = this.getCell(row, col); - if(cell){ + if (cell) { this.fly(cell).removeClass('x-grid3-cell-selected'); } }, // private - onColumnSplitterMoved : function(i, w){ + handleWheel : function(e) { + e.stopPropagation(); + }, + + /** + * @private + * Called by the SplitDragZone when a drag has been completed. Resizes the columns + */ + onColumnSplitterMoved : function(cellIndex, width) { this.userResized = true; - var cm = this.grid.colModel; - cm.setColumnWidth(i, w, true); + this.grid.colModel.setColumnWidth(cellIndex, width, true); - if(this.forceFit){ - this.fitColumns(true, false, i); + if (this.forceFit) { + this.fitColumns(true, false, cellIndex); this.updateAllColumnWidths(); - }else{ - this.updateColumnWidth(i, w); + } else { + this.updateColumnWidth(cellIndex, width); this.syncHeaderScroll(); } - this.grid.fireEvent('columnresize', i, w); + this.grid.fireEvent('columnresize', cellIndex, width); }, - // private - handleHdMenuClick : function(item){ - var index = this.hdCtxIndex, - cm = this.cm, - ds = this.ds, - id = item.getItemId(); - switch(id){ + /** + * @private + * Click handler for the shared column dropdown menu, called on beforeshow. Builds the menu + * which displays the list of columns for the user to show or hide. + */ + beforeColMenuShow : function() { + var colModel = this.cm, + colCount = colModel.getColumnCount(), + colMenu = this.colMenu, + i; + + colMenu.removeAll(); + + for (i = 0; i < colCount; i++) { + if (colModel.config[i].hideable !== false) { + colMenu.add(new Ext.menu.CheckItem({ + text : colModel.getColumnHeader(i), + itemId : 'col-' + colModel.getColumnId(i), + checked : !colModel.isHidden(i), + disabled : colModel.config[i].hideable === false, + hideOnClick: false + })); + } + } + }, + + /** + * @private + * Attached as the 'itemclick' handler to the header menu and the column show/hide submenu (if available). + * Performs sorting if the sorter buttons were clicked, otherwise hides/shows the column that was clicked. + */ + handleHdMenuClick : function(item) { + var store = this.ds, + dataIndex = this.cm.getDataIndex(this.hdCtxIndex); + + switch (item.getItemId()) { case 'asc': - ds.sort(cm.getDataIndex(index), 'ASC'); + store.sort(dataIndex, 'ASC'); break; case 'desc': - ds.sort(cm.getDataIndex(index), 'DESC'); + store.sort(dataIndex, 'DESC'); break; default: - index = cm.getIndexById(id.substr(4)); - if(index != -1){ - if(item.checked && cm.getColumnsBy(this.isHideableColumn, this).length <= 1){ - this.onDenyColumnHide(); - return false; - } - cm.setHidden(index, item.checked); - } + this.handleHdMenuClickDefault(item); } return true; }, - - // private - isHideableColumn : function(c){ - return !c.hidden; - }, - - // private - beforeColMenuShow : function(){ - var cm = this.cm, colCount = cm.getColumnCount(); - this.colMenu.removeAll(); - for(var i = 0; i < colCount; i++){ - if(cm.config[i].hideable !== false){ - this.colMenu.add(new Ext.menu.CheckItem({ - itemId: 'col-'+cm.getColumnId(i), - text: cm.getColumnHeader(i), - checked: !cm.isHidden(i), - hideOnClick:false, - disabled: cm.config[i].hideable === false - })); + + /** + * Called by handleHdMenuClick if any button except a sort ASC/DESC button was clicked. The default implementation provides + * the column hide/show functionality based on the check state of the menu item. A different implementation can be provided + * if needed. + * @param {Ext.menu.BaseItem} item The menu item that was clicked + */ + handleHdMenuClickDefault: function(item) { + var colModel = this.cm, + itemId = item.getItemId(), + index = colModel.getIndexById(itemId.substr(4)); + + if (index != -1) { + if (item.checked && colModel.getColumnsBy(this.isHideableColumn, this).length <= 1) { + this.onDenyColumnHide(); + return; } + colModel.setHidden(index, item.checked); } }, - // private - handleHdDown : function(e, t){ - if(Ext.fly(t).hasClass('x-grid3-hd-btn')){ + /** + * @private + * Called when a header cell is clicked - shows the menu if the click happened over a trigger button + */ + handleHdDown : function(e, target) { + if (Ext.fly(target).hasClass('x-grid3-hd-btn')) { e.stopEvent(); - var hd = this.findHeaderCell(t); - Ext.fly(hd).addClass('x-grid3-hd-menu-open'); - var index = this.getCellIndex(hd); + + var colModel = this.cm, + header = this.findHeaderCell(target), + index = this.getCellIndex(header), + sortable = colModel.isSortable(index), + menu = this.hmenu, + menuItems = menu.items, + menuCls = this.headerMenuOpenCls; + this.hdCtxIndex = index; - var ms = this.hmenu.items, cm = this.cm; - ms.get('asc').setDisabled(!cm.isSortable(index)); - ms.get('desc').setDisabled(!cm.isSortable(index)); - this.hmenu.on('hide', function(){ - Ext.fly(hd).removeClass('x-grid3-hd-menu-open'); + + Ext.fly(header).addClass(menuCls); + menuItems.get('asc').setDisabled(!sortable); + menuItems.get('desc').setDisabled(!sortable); + + menu.on('hide', function() { + Ext.fly(header).removeClass(menuCls); }, this, {single:true}); - this.hmenu.show(t, 'tl-bl?'); + + menu.show(target, 'tl-bl?'); } }, - // private - handleHdOver : function(e, t){ - var hd = this.findHeaderCell(t); - if(hd && !this.headersDisabled){ - this.activeHdRef = t; - this.activeHdIndex = this.getCellIndex(hd); - var fly = this.fly(hd); - this.activeHdRegion = fly.getRegion(); - if(!this.cm.isMenuDisabled(this.activeHdIndex)){ - fly.addClass('x-grid3-hd-over'); - this.activeHdBtn = fly.child('.x-grid3-hd-btn'); - if(this.activeHdBtn){ - this.activeHdBtn.dom.style.height = (hd.firstChild.offsetHeight-1)+'px'; + /** + * @private + * Attached to the headers' mousemove event. This figures out the CSS cursor to use based on where the mouse is currently + * pointed. If the mouse is currently hovered over the extreme left or extreme right of any header cell and the cell next + * to it is resizable it is given the resize cursor, otherwise the cursor is set to an empty string. + */ + handleHdMove : function(e) { + var header = this.findHeaderCell(this.activeHdRef); + + if (header && !this.headersDisabled) { + var handleWidth = this.splitHandleWidth || 5, + activeRegion = this.activeHdRegion, + headerStyle = header.style, + colModel = this.cm, + cursor = '', + pageX = e.getPageX(); + + if (this.grid.enableColumnResize !== false) { + var activeHeaderIndex = this.activeHdIndex, + previousVisible = this.getPreviousVisible(activeHeaderIndex), + currentResizable = colModel.isResizable(activeHeaderIndex), + previousResizable = previousVisible && colModel.isResizable(previousVisible), + inLeftResizer = pageX - activeRegion.left <= handleWidth, + inRightResizer = activeRegion.right - pageX <= (!this.activeHdBtn ? handleWidth : 2); + + if (inLeftResizer && previousResizable) { + cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported + } else if (inRightResizer && currentResizable) { + cursor = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize'; } } + + headerStyle.cursor = cursor; + } + }, + + /** + * @private + * Returns the index of the nearest currently visible header to the left of the given index. + * @param {Number} index The header index + * @return {Number/undefined} The index of the nearest visible header + */ + getPreviousVisible: function(index) { + while (index > 0) { + if (!this.cm.isHidden(index - 1)) { + return index; + } + index--; } + return undefined; }, - // private - handleHdMove : function(e, t){ - var hd = this.findHeaderCell(this.activeHdRef); - if(hd && !this.headersDisabled){ - var hw = this.splitHandleWidth || 5, - r = this.activeHdRegion, - x = e.getPageX(), - ss = hd.style, - cur = ''; - if(this.grid.enableColumnResize !== false){ - if(x - r.left <= hw && this.cm.isResizable(this.activeHdIndex-1)){ - cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'e-resize' : 'col-resize'; // col-resize not always supported - }else if(r.right - x <= (!this.activeHdBtn ? hw : 2) && this.cm.isResizable(this.activeHdIndex)){ - cur = Ext.isAir ? 'move' : Ext.isWebKit ? 'w-resize' : 'col-resize'; + /** + * @private + * Tied to the header element's mouseover event - adds the over class to the header cell if the menu is not disabled + * for that cell + */ + handleHdOver : function(e, target) { + var header = this.findHeaderCell(target); + + if (header && !this.headersDisabled) { + var fly = this.fly(header); + + this.activeHdRef = target; + this.activeHdIndex = this.getCellIndex(header); + this.activeHdRegion = fly.getRegion(); + + if (!this.isMenuDisabled(this.activeHdIndex, fly)) { + fly.addClass('x-grid3-hd-over'); + this.activeHdBtn = fly.child('.x-grid3-hd-btn'); + + if (this.activeHdBtn) { + this.activeHdBtn.dom.style.height = (header.firstChild.offsetHeight - 1) + 'px'; } } - ss.cursor = cur; } }, - // private - handleHdOut : function(e, t){ - var hd = this.findHeaderCell(t); - if(hd && (!Ext.isIE || !e.within(hd, true))){ + /** + * @private + * Tied to the header element's mouseout event. Removes the hover class from the header cell + */ + handleHdOut : function(e, target) { + var header = this.findHeaderCell(target); + + if (header && (!Ext.isIE || !e.within(header, true))) { this.activeHdRef = null; - this.fly(hd).removeClass('x-grid3-hd-over'); - hd.style.cursor = ''; + this.fly(header).removeClass('x-grid3-hd-over'); + header.style.cursor = ''; } }, + + /** + * @private + * Used by {@link #handleHdOver} to determine whether or not to show the header menu class on cell hover + * @param {Number} cellIndex The header cell index + * @param {Ext.Element} el The cell element currently being hovered over + */ + isMenuDisabled: function(cellIndex, el) { + return this.cm.isMenuDisabled(cellIndex); + }, - // private - hasRows : function(){ + /** + * @private + * Returns true if there are any rows rendered into the GridView + * @return {Boolean} True if any rows have been rendered + */ + hasRows : function() { var fc = this.mainBody.dom.firstChild; return fc && fc.nodeType == 1 && fc.className != 'x-grid-empty'; }, + + /** + * @private + */ + isHideableColumn : function(c) { + return !c.hidden; + }, - // back compat - bind : function(d, c){ + /** + * @private + * DEPRECATED - will be removed in Ext JS 5.0 + */ + bind : function(d, c) { this.initData(d, c); } }); @@ -1915,7 +2421,7 @@ viewConfig: { // private // This is a support class used internally by the Grid components Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, { - + constructor: function(grid, hd){ this.grid = grid; this.view = grid.getView(); @@ -1956,10 +2462,11 @@ Ext.grid.GridView.SplitDragZone = Ext.extend(Ext.dd.DDProxy, { var t = this.view.findHeaderCell(e.getTarget()); if(t && this.allowHeaderDrag(e)){ var xy = this.view.fly(t).getXY(), - x = xy[0], - y = xy[1]; - exy = e.getXY(), ex = exy[0], - w = t.offsetWidth, adjust = false; + x = xy[0], + exy = e.getXY(), + ex = exy[0], + w = t.offsetWidth, + adjust = false; if((ex - x) <= this.hw){ adjust = -1;