📄 gridview.js
字号:
/** * @class Ext.grid.GridView * @extends Ext.util.Observable * <p>This class encapsulates the user interface of an {@link Ext.grid.GridPanel}. * Methods of this class may be used to access user interface elements to enable * special display effects. Do not change the DOM structure of the user interface.</p> * <p>This class does not provide ways to manipulate the underlying data. The data * model of a Grid is held in an {@link Ext.data.Store}.</p> * @constructor * @param {Object} config */Ext.grid.GridView = function(config){ Ext.apply(this, config); // These events are only used internally by the grid components this.addEvents({ "beforerowremoved" : true, "beforerowsinserted" : true, "beforerefresh" : true, "rowremoved" : true, "rowsinserted" : true, "rowupdated" : true, "refresh" : true }); Ext.grid.GridView.superclass.constructor.call(this);};Ext.extend(Ext.grid.GridView, Ext.util.Observable, { /** * Override this function to apply custom CSS classes to rows during rendering. You can also supply custom * parameters to the row template for the current row to customize how it is rendered using the <b>rowParams</b> * parameter. This function should return the CSS class name (or empty string '' for none) that will be added * to the row's wrapping div. To apply multiple class names, simply return them space-delimited within the string * (e.g., 'my-class another-class'). * @param {Record} record The {@link Ext.data.Record} corresponding to the current row * @param {Number} index The row index * @param {Object} rowParams A config object that is passed to the row template during rendering that allows * customization of various aspects of a body row, if applicable. Note that this object will only be applied if * {@link #enableRowBody} = true, otherwise it will be ignored. The object may contain any of these properties:<ul> * <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> * <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> * <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 * column count of the grid).</div></li> * </ul> * @param {Store} ds The {@link Ext.data.Store} this grid is bound to * @method getRowClass */ /** * @cfg {Boolean} enableRowBody True to add a second TR element per row that can be used to provide a row body * that spans beneath the data row. Use the {@link #getRowClass} method's rowParams config to customize the row body. */ /** * The amount of space to reserve for the scrollbar (defaults to 19 pixels) * @type Number */ scrollOffset: 19, /** * @cfg {Boolean} autoFill True to auto expand the columns to fit the grid <b>when the grid is created</b>. */ autoFill: false, /** * @cfg {Boolean} forceFit True to auto expand/contract the size of the columns to fit the grid width and prevent horizontal scrolling. */ forceFit: false, /** * The CSS classes applied to a header when it is sorted. (defaults to ["sort-asc", "sort-desc"]) * @type Array */ sortClasses : ["sort-asc", "sort-desc"], /** * The text displayed in the "Sort Ascending" menu item * @type String */ sortAscText : "Sort Ascending", /** * The text displayed in the "Sort Descending" menu item * @type String */ sortDescText : "Sort Descending", /** * The text displayed in the "Columns" menu item * @type String */ columnsText : "Columns", // private borderWidth: 2, /* -------------------------------- UI Specific ----------------------------- */ // private initTemplates : function(){ var ts = this.templates || {}; if(!ts.master){ ts.master = new Ext.Template( '<div class="x-grid3" hidefocus="true">', '<div class="x-grid3-viewport">', '<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>', '<div class="x-grid3-scroller"><div class="x-grid3-body">{body}</div><a href="#" class="x-grid3-focus" tabIndex="-1"></a></div>', "</div>", '<div class="x-grid3-resize-proxy"> </div>', "</div>" ); } if(!ts.header){ ts.header = new Ext.Template( '<table border="0" cellspacing="0" cellpadding="0" style="{tstyle}">', '<thead><tr class="x-grid3-hd-row">{cells}</tr></thead>', "</table>" ); } if(!ts.hcell){ ts.hcell = new Ext.Template( '<td class="x-grid3-hd x-grid3-cell x-grid3-td-{id}" style="{style}"><div {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>' : '', '{value}<img class="x-grid3-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" />', "</div></td>" ); } if(!ts.body){ ts.body = new Ext.Template('{rows}'); } if(!ts.row){ ts.row = new Ext.Template( '<div class="x-grid3-row {alt}" style="{tstyle}"><table class="x-grid3-row-table" border="0" cellspacing="0" cellpadding="0" style="{tstyle}">', '<tbody><tr>{cells}</tr>', (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>' : ''), '</tbody></table></div>' ); } if(!ts.cell){ ts.cell = new Ext.Template( '<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} {css}" style="{style}" tabIndex="0" {cellAttr}>', '<div class="x-grid3-cell-inner x-grid3-col-{id}" unselectable="on" {attr}>{value}</div>', "</td>" ); } for(var k in ts){ var t = ts[k]; if(t && typeof t.compile == 'function' && !t.compiled){ t.disableFormats = true; t.compile(); } } this.templates = ts; this.tdClass = 'x-grid3-cell'; this.cellSelector = 'td.x-grid3-cell'; this.hdCls = 'x-grid3-hd'; this.rowSelector = 'div.x-grid3-row'; this.colRe = new RegExp("x-grid3-td-([^\\s]+)", ""); }, // private fly : function(el){ if(!this._flyweight){ this._flyweight = new Ext.Element.Flyweight(document.body); } this._flyweight.dom = el; return this._flyweight; }, // private getEditorParent : function(ed){ 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); this.innerHd = this.mainHd.dom.firstChild; this.scroller = new E(this.mainWrap.dom.childNodes[1]); if(this.forceFit){ this.scroller.setStyle('overflow-x', 'hidden'); } this.mainBody = new E(this.scroller.dom.firstChild); this.focusEl = new E(this.scroller.dom.childNodes[1]); this.focusEl.swallowEvent("click", true); this.resizeProxy = new E(cs[1]); }, // private getRows : function(){ return this.hasRows() ? this.mainBody.dom.childNodes : []; }, // finder methods, used with delegation // private findCell : function(el){ if(!el){ return false; } return this.fly(el).findParent(this.cellSelector, 3); }, // private findCellIndex : function(el, requiredCls){ var cell = this.findCell(el); if(cell && (!requiredCls || this.fly(cell).hasClass(requiredCls))){ 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]); } } return false; }, // private findHeaderCell : function(el){ var cell = this.findCell(el); return cell && this.fly(cell).hasClass(this.hdCls) ? cell : null; }, // private findHeaderIndex : function(el){ return this.findCellIndex(el, this.hdCls); }, // private findRow : function(el){ if(!el){ return false; } return this.fly(el).findParent(this.rowSelector, 10); }, // private findRowIndex : function(el){ var r = this.findRow(el); return r ? r.rowIndex : false; }, // getter methods for fetching elements dynamically in the grid/** * Return the <TR> HtmlElement which represents a Grid row for the specified index. * @param {Number} index The row index * @return {HtmlElement} The <TR> element. */ getRow : function(row){ return this.getRows()[row]; },/** * Returns the grid's <TD> HtmlElement at the specified coordinates. * @param {Number} row The row index in which to find the cell. * @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]; },/** * Return the <TD> HtmlElement which represents the Grid's header cell for the specified column index. * @param {Number} index The column index * @return {HtmlElement} The <TD> element. */ 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); } }, // private removeRowClass : function(row, cls){ var r = this.getRow(row); if(r){ this.fly(r).removeClass(cls); } }, // private removeRow : function(row){ var r = this.getRow(row); if(r){ r.parentNode.removeChild(r); } }, // private removeRows : function(firstRow, lastRow){ var bd = this.mainBody.dom; for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){ bd.removeChild(bd.childNodes[firstRow]); } }, // scrolling stuff // private getScrollState : function(){ var sb = this.scroller.dom; return {left: sb.scrollLeft, top: sb.scrollTop}; }, // private restoreScroll : function(state){ var sb = this.scroller.dom; sb.scrollLeft = state.left; sb.scrollTop = state.top; }, /** * 滚动grid到顶部 */ /** * Scrolls the grid to the top */ scrollToTop : function(){ this.scroller.dom.scrollTop = 0; this.scroller.dom.scrollLeft = 0; }, // private syncScroll : function(){ var mb = this.scroller.dom; this.innerHd.scrollLeft = mb.scrollLeft; this.grid.fireEvent("bodyscroll", mb.scrollLeft, mb.scrollTop); }, // 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 updateAllColumnWidths : function(){ var tw = this.getTotalWidth(); var clen = this.cm.getColumnCount(); var ws = []; for(var i = 0; i < clen; i++){ ws[i] = this.getColumnWidth(i); } this.innerHd.firstChild.firstChild.style.width = tw; for(var i = 0; i < clen; i++){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -