📄 gridview2.js
字号:
sb.scrollLeft = state.left;
sb.scrollTop = state.top;
this.syncScroll();
},
syncScroll : function(){
var sb = this.scroller.dom;
var sh = this.mainHd.dom;
var bs = this.mainBody.dom;
var lv = this.lockedBody.dom;
sh.scrollLeft = bs.scrollLeft = sb.scrollLeft;
lv.scrollTop = bs.scrollTop = sb.scrollTop;
},
handleScroll : function(e){
this.syncScroll();
var sb = this.scroller.dom;
this.grid.fireEvent("bodyscroll", sb.scrollLeft, sb.scrollTop);
e.stopEvent();
},
handleWheel : function(e){
var d = e.getWheelDelta();
this.scroller.dom.scrollTop -= d*22;
// set this here to prevent jumpy scrolling on large tables
this.lockedBody.dom.scrollTop = this.mainBody.dom.scrollTop = this.scroller.dom.scrollTop;
e.stopEvent();
},
renderRows : function(startRow, endRow){
// pull in all the crap needed to render rows
var g = this.grid, cm = g.colModel, ds = g.dataSource, stripe = g.stripeRows;
var colCount = cm.getColumnCount();
if(ds.getCount() < 1){
return ["", ""];
}
// build a map for all the columns
var cs = [];
for(var i = 0; i < colCount; i++){
var name = cm.getDataIndex(i);
cs[i] = {
name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
renderer : cm.getRenderer(i),
id : cm.getColumnId(i),
locked : cm.isLocked(i)
};
}
startRow = startRow || 0;
endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
// records to render
var rs = ds.getRange(startRow, endRow);
return this.doRender(cs, rs, ds, startRow, colCount, stripe);
},
// As much as I hate to duplicate code, this was branched because FireFox really hates
// [].join("") on strings. The performance difference was substantial enough to
// branch this function
doRender : Ext.isGecko ?
function(cs, rs, ds, startRow, colCount, stripe){
var ts = this.templates, ct = ts.cell, rt = ts.row;
// buffers
var buf = "", lbuf = "", cb, lcb, c, p = {}, rp = {}, r, rowIndex;
for(var j = 0, len = rs.length; j < len; j++){
r = rs[j]; cb = ""; lcb = ""; rowIndex = (j+startRow);
for(var i = 0; i < colCount; i++){
c = cs[i];
p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
p.id = c.id;
p.css = p.attr = "";
p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
if(p.value == undefined || p.value === "") p.value = " ";
if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
}
var markup = ct.apply(p);
if(!c.locked){
cb+= markup;
}else{
lcb+= markup;
}
}
var alt = [];
if(stripe && ((rowIndex+1) % 2 == 0)){
alt[0] = "x-grid-row-alt";
}
if(r.dirty){
alt[1] = " x-grid-dirty-row";
}
rp.cells = lcb;
if(this.getRowClass){
alt[2] = this.getRowClass(r, rowIndex);
}
rp.alt = alt.join(" ");
lbuf+= rt.apply(rp);
rp.cells = cb;
buf+= rt.apply(rp);
}
return [lbuf, buf];
} :
function(cs, rs, ds, startRow, colCount, stripe){
var ts = this.templates, ct = ts.cell, rt = ts.row;
// buffers
var buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r, rowIndex;
for(var j = 0, len = rs.length; j < len; j++){
r = rs[j]; cb = []; lcb = []; rowIndex = (j+startRow);
for(var i = 0; i < colCount; i++){
c = cs[i];
p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
p.id = c.id;
p.css = p.attr = "";
p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
if(p.value == undefined || p.value === "") p.value = " ";
if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
}
var markup = ct.apply(p);
if(!c.locked){
cb[cb.length] = markup;
}else{
lcb[lcb.length] = markup;
}
}
var alt = [];
if(stripe && ((rowIndex+1) % 2 == 0)){
alt[0] = "x-grid-row-alt";
}
if(r.dirty){
alt[1] = " x-grid-dirty-row";
}
rp.cells = lcb;
if(this.getRowClass){
alt[2] = this.getRowClass(r, rowIndex);
}
rp.alt = alt.join(" ");
rp.cells = lcb.join("");
lbuf[lbuf.length] = rt.apply(rp);
rp.cells = cb.join("");
buf[buf.length] = rt.apply(rp);
}
return [lbuf.join(""), buf.join("")];
},
renderBody : function(){
var markup = this.renderRows();
var bt = this.templates.body;
return [bt.apply({rows: markup[0]}), bt.apply({rows: markup[1]})];
},
/**
* Refreshes the grid
* @param {Boolean} headersToo
*/
refresh : function(headersToo){
this.fireEvent("beforerefresh", this);
this.grid.stopEditing();
var result = this.renderBody();
this.lockedBody.update(result[0]);
this.mainBody.update(result[1]);
if(headersToo === true){
this.updateHeaders();
this.updateColumns();
this.updateSplitters();
this.updateHeaderSortState();
}
this.syncRowHeights();
this.layout();
this.fireEvent("refresh", this);
},
handleColumnMove : function(cm, oldIndex, newIndex){
this.indexMap = null;
var s = this.getScrollState();
this.refresh(true);
this.restoreScroll(s);
this.afterMove(newIndex);
},
afterMove : function(colIndex){
if(this.enableMoveAnim && Ext.enableFx){
this.fly(this.getHeaderCell(colIndex).firstChild).highlight(this.hlColor);
}
},
updateCell : function(dm, rowIndex, dataIndex){
var colIndex = this.getColumnIndexByDataIndex(dataIndex);
if(typeof colIndex == "undefined"){ // not present in grid
return;
}
var cm = this.grid.colModel;
var cell = this.getCell(rowIndex, colIndex);
var cellText = this.getCellText(rowIndex, colIndex);
var p = {
cellId : "x-grid-cell-" + rowIndex + "-" + colIndex,
id : cm.getColumnId(colIndex),
css: colIndex == cm.getColumnCount()-1 ? "x-grid-col-last" : ""
};
var renderer = cm.getRenderer(colIndex);
var val = renderer(dm.getValueAt(rowIndex, dataIndex), p, rowIndex, colIndex, dm);
if(typeof val == "undefined" || val === "") val = " ";
cellText.innerHTML = val;
cell.className = this.cellClass + " " + p.cellId + " " + p.css;
this.syncRowHeights(rowIndex, rowIndex);
},
calcColumnWidth : function(colIndex, maxRowsToMeasure){
var maxWidth = 0;
if(this.grid.autoSizeHeaders){
var h = this.getHeaderCellMeasure(colIndex);
maxWidth = Math.max(maxWidth, h.scrollWidth);
}
var tb, index;
if(this.cm.isLocked(colIndex)){
tb = this.getLockedTable();
index = colIndex;
}else{
tb = this.getBodyTable();
index = colIndex - this.cm.getLockedCount();
}
if(tb && tb.rows){
var rows = tb.rows;
var stopIndex = Math.min(maxRowsToMeasure || rows.length, rows.length);
for(var i = 0; i < stopIndex; i++){
var cell = rows[i].childNodes[index].firstChild;
maxWidth = Math.max(maxWidth, cell.scrollWidth);
}
}
return maxWidth + /*margin for error in IE*/ 5;
},
/**
* Autofit a column to its content.
* @param {Number} colIndex
* @param {Boolean} forceMinSize true to force the column to go smaller if possible
*/
autoSizeColumn : function(colIndex, forceMinSize, suppressEvent){
if(this.cm.isHidden(colIndex)){
return; // can't calc a hidden column
}
if(forceMinSize){
var cid = this.cm.getColumnId(colIndex);
this.css.updateRule(this.colSelector + cid, "width", this.grid.minColumnWidth + "px");
if(this.grid.autoSizeHeaders){
this.css.updateRule(this.hdSelector + cid, "width", this.grid.minColumnWidth + "px");
}
}
var newWidth = this.calcColumnWidth(colIndex);
this.cm.setColumnWidth(colIndex,
Math.max(this.grid.minColumnWidth, newWidth), suppressEvent);
if(!suppressEvent){
this.grid.fireEvent("columnresize", colIndex, newWidth);
}
},
/**
* Autofits all columns to their content and then expands to fit any extra space in the grid
*/
autoSizeColumns : function(){
var cm = this.grid.colModel;
var colCount = cm.getColumnCount();
for(var i = 0; i < colCount; i++){
this.autoSizeColumn(i, true, true);
}
if(cm.getTotalWidth() < this.scroller.dom.clientWidth){
this.fitColumns();
}else{
this.updateColumns();
this.layout();
}
},
/**
* Autofits all columns to the grid's width proportionate with their current size
* @param {Boolean} reserveScrollSpace Reserve space for a scrollbar
*/
fitColumns : function(reserveScrollSpace){
var cm = this.grid.colModel;
var colCount = cm.getColumnCount();
var cols = [];
var width = 0;
var i, w;
for (i = 0; i < colCount; i++){
if(!cm.isHidden(i) && !cm.isFixed(i)){
w = cm.getColumnWidth(i);
cols.push(i);
cols.push(w);
width += w;
}
}
var avail = Math.min(this.scroller.dom.clientWidth, this.el.getWidth());
if(reserveScrollSpace){
avail -= 17;
}
var frac = (avail - cm.getTotalWidth())/width;
while (cols.length){
w = cols.pop();
i = cols.pop();
cm.setColumnWidth(i, Math.floor(w + w*frac), true);
}
this.updateColumns();
this.layout();
},
onRowSelect : function(rowIndex){
var row = this.getRowComposite(rowIndex);
row.addClass("x-grid-row-selected");
},
onRowDeselect : function(rowIndex){
var row = this.getRowComposite(rowIndex);
row.removeClass("x-grid-row-selected");
},
onCellSelect : function(row, col){
var cell = this.getCell(row, col);
if(cell){
Ext.fly(cell).addClass("x-grid-cell-selected");
}
},
onCellDeselect : function(row, col){
var cell = this.getCell(row, col);
if(cell){
Ext.fly(cell).removeClass("x-grid-cell-selected");
}
},
updateHeaderSortState : function(){
var state = this.ds.getSortState();
if(!state){
return;
}
this.sortState = state;
var sortColumn = this.cm.findColumnIndex(state.field);
if(sortColumn != -1){
var sortDir = state.direction;
var sc = this.sortClasses;
var hds = this.el.select(this.headerSelector).removeClass(sc);
hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
}
},
handleHeaderClick : function(g, index){
if(this.headersDisabled){
return;
}
var dm = g.store, cm = g.colModel;
if(!cm.isSortable(index)){
return;
}
g.stopEditing();
dm.sort(cm.getDataIndex(index));
},
destroy : function(){
if(this.colMenu){
this.colMenu.removeAll();
Ext.menu.MenuMgr.unregister(this.colMenu);
this.colMenu.getEl().remove();
delete this.colMenu;
}
if(this.hmenu){
this.hmenu.removeAll();
Ext.menu.MenuMgr.unregister(this.hmenu);
this.hmenu.getEl().remove();
delete this.hmenu;
}
if(this.grid.enableColumnMove){
var dds = Ext.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
if(dds){
for(var dd in dds){
if(!dds[dd].config.isTarget && dds[dd].dragElId){
var elid = dds[dd].dragElId;
dds[dd].unreg();
Ext.get(elid).remove();
} else if(dds[dd].config.isTarget){
dds[dd].proxyTop.remove();
dds[dd].proxyBottom.remove();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -