📄 gridview.js
字号:
var hd = this.getHeaderCell(i); hd.style.width = ws[i]; } var ns = this.getRows(); for(var i = 0, len = ns.length; i < len; i++){ ns[i].style.width = tw; ns[i].firstChild.style.width = tw; var row = ns[i].firstChild.rows[0]; for(var j = 0; j < clen; j++){ row.childNodes[j].style.width = ws[j]; } } this.onAllColumnWidthsUpdated(ws, tw); }, // private updateColumnWidth : function(col, width){ var w = this.getColumnWidth(col); var tw = this.getTotalWidth(); this.innerHd.firstChild.firstChild.style.width = tw; var hd = this.getHeaderCell(col); hd.style.width = w; var ns = this.getRows(); for(var i = 0, len = ns.length; i < len; i++){ ns[i].style.width = tw; ns[i].firstChild.style.width = tw; ns[i].firstChild.rows[0].childNodes[col].style.width = w; } this.onColumnWidthUpdated(col, w, tw); }, // private updateColumnHidden : function(col, hidden){ var tw = this.getTotalWidth(); this.innerHd.firstChild.firstChild.style.width = tw; var display = hidden ? 'none' : ''; var hd = this.getHeaderCell(col); hd.style.display = display; var ns = this.getRows(); for(var i = 0, len = ns.length; i < len; i++){ ns[i].style.width = tw; ns[i].firstChild.style.width = tw; ns[i].firstChild.rows[0].childNodes[col].style.display = display; } this.onColumnHiddenUpdated(col, hidden, tw); delete this.lastViewWidth; // force recalc this.layout(); }, // private doRender : function(cs, rs, ds, startRow, colCount, stripe){ var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1; var tstyle = 'width:'+this.getTotalWidth()+';'; // buffers var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r; for(var j = 0, len = rs.length; j < len; j++){ r = rs[j]; cb = []; var rowIndex = (j+startRow); for(var i = 0; i < colCount; i++){ c = cs[i]; p.id = c.id; p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : ''); p.attr = p.cellAttr = ""; p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds); p.style = c.style; if(p.value == undefined || p.value === "") p.value = " "; if(r.dirty && typeof r.modified[c.name] !== 'undefined'){ p.css += ' x-grid3-dirty-cell'; } cb[cb.length] = ct.apply(p); } var alt = []; if(stripe && ((rowIndex+1) % 2 == 0)){ alt[0] = "x-grid3-row-alt"; } if(r.dirty){ alt[1] = " x-grid3-dirty-row"; } rp.cols = colCount; if(this.getRowClass){ alt[2] = this.getRowClass(r, rowIndex, rp, ds); } rp.alt = alt.join(" "); rp.cells = cb.join(""); buf[buf.length] = rt.apply(rp); } return buf.join(""); }, // private processRows : function(startRow, skipStripe){ if(this.ds.getCount() < 1){ return; } skipStripe = skipStripe || !this.grid.stripeRows; startRow = startRow || 0; var rows = this.getRows(); var cls = ' x-grid3-row-alt '; for(var i = startRow, len = rows.length; i < len; i++){ var row = rows[i]; row.rowIndex = i; if(!skipStripe){ var isAlt = ((i+1) % 2 == 0); var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1; if(isAlt == hasAlt){ continue; } if(isAlt){ row.className += " x-grid3-row-alt"; }else{ row.className = row.className.replace("x-grid3-row-alt", ""); } } } }, // private renderUI : function(){ var header = this.renderHeaders(); var body = this.templates.body.apply({rows:''}); var html = this.templates.master.apply({ body: body, header: header }); var g = this.grid; g.getGridEl().dom.innerHTML = html; this.initElements(); this.mainBody.dom.innerHTML = this.renderRows(); this.processRows(0, true); // get mousedowns early Ext.fly(this.innerHd).on("click", this.handleHdDown, this); this.mainHd.on("mouseover", this.handleHdOver, this); this.mainHd.on("mouseout", this.handleHdOut, this); this.mainHd.on("mousemove", this.handleHdMove, this); this.scroller.on('scroll', this.syncScroll, this); if(g.enableColumnResize !== false){ new Ext.grid.GridView.SplitDragZone(g, this.mainHd.dom); } if(g.enableColumnMove){ this.columnDrag = new Ext.grid.GridView.ColumnDragZone(g, this.innerHd); this.columnDrop = new Ext.grid.HeaderDropZone(g, this.mainHd.dom); } if(g.enableHdMenu !== false){ if(g.enableColumnHide !== false){ this.colMenu = new Ext.menu.Menu({id:g.id + "-hcols-menu"}); this.colMenu.on("beforeshow", this.beforeColMenuShow, this); this.colMenu.on("itemclick", this.handleHdMenuClick, this); } this.hmenu = new Ext.menu.Menu({id: g.id + "-hctx"}); this.hmenu.add( {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"}, {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"} ); if(g.enableColumnHide !== false){ this.hmenu.add('-', {id:"columns", text: this.columnsText, menu: this.colMenu, iconCls: 'x-cols-icon'} ); } this.hmenu.on("itemclick", this.handleHdMenuClick, this); //g.on("headercontextmenu", this.handleHdCtx, this); } if(g.enableDragDrop || g.enableDrag){ var dd = new Ext.grid.GridDragZone(g, { ddGroup : g.ddGroup || 'GridDD' }); } this.updateHeaderSortState(); }, // private layout : function(){ if(!this.mainBody){ return; // not rendered } var g = this.grid; var c = g.getGridEl(), cm = this.cm, expandCol = g.autoExpandColumn, gv = this; var csize = c.getSize(true); var vw = csize.width; if(!vw || !csize.height){ // display: none? return; } if(g.autoHeight){ this.scroller.dom.style.overflow = 'visible'; }else{ this.el.setSize(csize.width, csize.height); var hdHeight = this.mainHd.getHeight(); var vh = csize.height - (hdHeight); this.scroller.setSize(vw, vh); this.innerHd.style.width = (vw)+'px'; } if(this.forceFit){ if(this.lastViewWidth != vw){ this.fitColumns(false, false); this.lastViewWidth = vw; } }else { this.autoExpand(); } this.onLayout(vw, vh); }, // template functions for subclasses and plugins // these functions include precalculated values onLayout : function(vw, vh){ // do nothing }, onColumnWidthUpdated : function(col, w, tw){ }, onAllColumnWidthsUpdated : function(ws, tw){ }, onColumnHiddenUpdated : function(col, hidden, tw){ }, updateColumnText : function(col, text){ }, afterMove : function(colIndex){ }, /* ----------------------------------- Core Specific -------------------------------------------*/ // private init: function(grid){ this.grid = grid; this.initTemplates(); this.initData(grid.store, grid.colModel); this.initUI(grid); }, // private getColumnId : function(index){ return this.cm.getColumnId(index); }, // private renderHeaders : function(){ var cm = this.cm, ts = this.templates; var ct = ts.hcell; var cb = [], sb = [], p = {}; for(var i = 0, len = cm.getColumnCount(); i < len; i++){ p.id = cm.getColumnId(i); p.value = cm.getColumnHeader(i) || ""; p.style = this.getColumnStyle(i, true); if(cm.config[i].align == 'right'){ p.istyle = 'padding-right:16px'; } cb[cb.length] = ct.apply(p); } return ts.header.apply({cells: cb.join(""), tstyle:'width:'+this.getTotalWidth()+';'}); }, // private beforeUpdate : function(){ this.grid.stopEditing(); }, // private updateHeaders : function(){ this.innerHd.firstChild.innerHTML = this.renderHeaders(); }, /** * Focuses the specified row.. * @param {Number} row The row index */ focusRow : function(row){ this.focusCell(row, 0, false); }, /** * Focuses the specified cell. * @param {Number} row The row index * @param {Number} col The column index */ focusCell : function(row, col, hscroll){ var el = this.ensureVisible(row, col, hscroll); if(el){ this.focusEl.alignTo(el, "tl-tl"); if(Ext.isGecko){ this.focusEl.focus(); }else{ this.focusEl.focus.defer(1, this.focusEl); } } }, // private ensureVisible : function(row, col, hscroll){ if(typeof row != "number"){ row = row.rowIndex; } if(row < 0 || row >= this.ds.getCount()){ return; } col = (col !== undefined ? col : 0); var rowEl = this.getRow(row), cellEl; if(!(hscroll === false && col === 0)){ while(this.cm.isHidden(col)){ col++; } cellEl = this.getCell(row, col); } if(!rowEl){ return; } var c = this.scroller.dom; var ctop = 0; var p = rowEl, stop = this.el.dom; while(p && p != stop){ ctop += p.offsetTop; p = p.offsetParent; } ctop -= this.mainHd.dom.offsetHeight; var cbot = ctop + rowEl.offsetHeight; var ch = c.clientHeight; var stop = parseInt(c.scrollTop, 10); var sbot = stop + ch; if(ctop < stop){ c.scrollTop = ctop; }else if(cbot > sbot){ c.scrollTop = cbot-ch; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -