📄 gridview2.js
字号:
/*
* Ext JS Library 2.0
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
Ext.grid.GridView = function(config){
Ext.grid.GridView.superclass.constructor.call(this);
this.el = null;
Ext.apply(this, config);
};
Ext.extend(Ext.grid.GridView, Ext.grid.AbstractGridView, {
/**
* Override this function to apply custom css classes to rows during rendering
* @param {Record} record The record
* @param {Number} index
* @method getRowClass
*/
rowClass : "x-grid-row",
cellClass : "x-grid-col",
tdClass : "x-grid-td",
hdClass : "x-grid-hd",
splitClass : "x-grid-split",
sortClasses : ["sort-asc", "sort-desc"],
enableMoveAnim : false,
hlColor: "C3DAF9",
dh : Ext.DomHelper,
fly : Ext.Element.fly,
css : Ext.util.CSS,
borderWidth: 1,
splitOffset: 3,
scrollIncrement : 22,
cellRE: /(?:.*?)x-grid-(?:hd|cell|csplit)-(?:[\d]+)-([\d]+)(?:.*?)/,
findRE: /\s?(?:x-grid-hd|x-grid-col|x-grid-csplit)\s/,
getEditorParent : function(ed){
return ed.parentEl || document.body;
},
bind : function(ds, cm){
if(this.ds){
this.ds.un("load", this.onLoad, this);
this.ds.un("datachanged", this.onDataChange);
this.ds.un("add", this.onAdd);
this.ds.un("remove", this.onRemove);
this.ds.un("update", this.onUpdate);
this.ds.un("clear", this.onClear);
}
if(ds){
ds.on("load", this.onLoad, this);
ds.on("datachanged", this.onDataChange, this);
ds.on("add", this.onAdd, this);
ds.on("remove", this.onRemove, this);
ds.on("update", this.onUpdate, this);
ds.on("clear", this.onClear, this);
}
this.ds = ds;
if(this.cm){
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);
this.cm.un("columnlockchange", this.onColumnLock, this);
}
if(cm){
this.generateRules(cm);
cm.on("widthchange", this.onColWidthChange, this);
cm.on("headerchange", this.onHeaderChange, this);
cm.on("hiddenchange", this.onHiddenChange, this);
cm.on("columnmoved", this.onColumnMove, this);
cm.on("columnlockchange", this.onColumnLock, this);
}
this.cm = cm;
},
init: function(grid){
Ext.grid.GridView.superclass.init.call(this, grid);
this.bind(grid.dataSource, grid.colModel);
grid.on("headerclick", this.handleHeaderClick, this);
if(grid.trackMouseOver){
grid.on("mouseover", this.onRowOver, this);
grid.on("mouseout", this.onRowOut, this);
}
grid.cancelTextSelection = function(){};
this.gridId = grid.id;
var tpls = this.templates || {};
if(!tpls.master){
tpls.master = new Ext.Template(
'<div class="x-grid" hidefocus="true">',
'<div class="x-grid-topbar"></div>',
'<div class="x-grid-scroller"><div></div></div>',
'<div class="x-grid-locked">',
'<div class="x-grid-header">{lockedHeader}</div>',
'<div class="x-grid-body">{lockedBody}</div>',
"</div>",
'<div class="x-grid-viewport">',
'<div class="x-grid-header">{header}</div>',
'<div class="x-grid-body">{body}</div>',
"</div>",
'<div class="x-grid-bottombar"></div>',
'<a href="#" class="x-grid-focus" tabIndex="-1"></a>',
'<div class="x-grid-resize-proxy"> </div>',
"</div>"
);
tpls.master.disableformats = true;
}
if(!tpls.header){
tpls.header = new Ext.Template(
'<table border="0" cellspacing="0" cellpadding="0">',
'<tbody><tr class="x-grid-hd-row">{cells}</tr></tbody>',
"</table>{splits}"
);
tpls.header.disableformats = true;
}
tpls.header.compile();
if(!tpls.hcell){
tpls.hcell = new Ext.Template(
'<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
'<div class="x-grid-hd-text" unselectable="on">{value}<img class="x-grid-sort-icon" src="', Ext.BLANK_IMAGE_URL, '" /></div>',
"</div></td>"
);
tpls.hcell.disableFormats = true;
}
tpls.hcell.compile();
if(!tpls.hsplit){
tpls.hsplit = new Ext.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style}" unselectable="on"> </div>');
tpls.hsplit.disableFormats = true;
}
tpls.hsplit.compile();
if(!tpls.body){
tpls.body = new Ext.Template(
'<table border="0" cellspacing="0" cellpadding="0">',
"<tbody>{rows}</tbody>",
"</table>"
);
tpls.body.disableFormats = true;
}
tpls.body.compile();
if(!tpls.row){
tpls.row = new Ext.Template('<tr class="x-grid-row {alt}">{cells}</tr>');
tpls.row.disableFormats = true;
}
tpls.row.compile();
if(!tpls.cell){
tpls.cell = new Ext.Template(
'<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
'<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text" unselectable="on" {attr}>{value}</div></div>',
"</td>"
);
tpls.cell.disableFormats = true;
}
tpls.cell.compile();
this.templates = tpls;
},
// remap these for backwards compat
onColWidthChange : function(){
this.updateColumns.apply(this, arguments);
},
onHeaderChange : function(){
this.updateHeaders.apply(this, arguments);
},
onHiddenChange : function(){
this.handleHiddenChange.apply(this, arguments);
},
onColumnMove : function(){
this.handleColumnMove.apply(this, arguments);
},
onColumnLock : function(){
this.handleLockChange.apply(this, arguments);
},
onDataChange : function(){
this.refresh();
this.updateHeaderSortState();
},
onClear : function(){
this.refresh();
},
onUpdate : function(ds, record){
this.refreshRow(record);
},
refreshRow : function(record){
var ds = this.ds, index;
if(typeof record == 'number'){
index = record;
record = ds.getAt(index);
}else{
index = ds.indexOf(record);
}
this.insertRows(ds, index, index, true);
this.onRemove(ds, record, index+1, true);
this.syncRowHeights(index, index);
this.layout();
this.fireEvent("rowupdated", this, index, record);
},
onAdd : function(ds, records, index){
this.insertRows(ds, index, index + (records.length-1));
},
onRemove : function(ds, record, index, isUpdate){
if(isUpdate !== true){
this.fireEvent("beforerowremoved", this, index, record);
}
var bt = this.getBodyTable(), lt = this.getLockedTable();
if(bt.rows[index]){
bt.firstChild.removeChild(bt.rows[index]);
}
if(lt.rows[index]){
lt.firstChild.removeChild(lt.rows[index]);
}
if(isUpdate !== true){
this.stripeRows(index);
this.syncRowHeights(index, index);
this.layout();
this.fireEvent("rowremoved", this, index, record);
}
},
onLoad : function(){
this.scrollToTop();
},
/**
* Scrolls the grid to the top
*/
scrollToTop : function(){
if(this.scroller){
this.scroller.dom.scrollTop = 0;
this.syncScroll();
}
},
/**
* Gets a panel in the header of the grid that can be used for toolbars etc.
* After modifying the contents of this panel a call to grid.autoSize() may be
* required to register any changes in size.
* @param {Boolean} doShow By default the header is hidden. Pass true to show the panel
* @return Ext.Element
*/
getHeaderPanel : function(doShow){
if(doShow){
this.headerPanel.show();
}
return this.headerPanel;
},
/**
* Gets a panel in the footer of the grid that can be used for toolbars etc.
* After modifying the contents of this panel a call to grid.autoSize() may be
* required to register any changes in size.
* @param {Boolean} doShow By default the footer is hidden. Pass true to show the panel
* @return Ext.Element
*/
getFooterPanel : function(doShow){
if(doShow){
this.footerPanel.show();
}
return this.footerPanel;
},
initElements : function(){
var E = Ext.Element;
var el = this.grid.getGridEl().dom.firstChild;
var cs = el.childNodes;
this.el = new E(el);
this.headerPanel = new E(el.firstChild);
this.headerPanel.enableDisplayMode("block");
this.scroller = new E(cs[1]);
this.scrollSizer = new E(this.scroller.dom.firstChild);
this.lockedWrap = new E(cs[2]);
this.lockedHd = new E(this.lockedWrap.dom.firstChild);
this.lockedBody = new E(this.lockedWrap.dom.childNodes[1]);
this.mainWrap = new E(cs[3]);
this.mainHd = new E(this.mainWrap.dom.firstChild);
this.mainBody = new E(this.mainWrap.dom.childNodes[1]);
this.footerPanel = new E(cs[4]);
this.footerPanel.enableDisplayMode("block");
this.focusEl = new E(cs[5]);
this.focusEl.swallowEvent("click", true);
this.resizeProxy = new E(cs[6]);
this.headerSelector = String.format(
'#{0} td.x-grid-hd, #{1} td.x-grid-hd',
this.lockedHd.id, this.mainHd.id
);
this.splitterSelector = String.format(
'#{0} div.x-grid-split, #{1} div.x-grid-split',
this.lockedHd.id, this.mainHd.id
);
},
getHeaderCell : function(index){
return Ext.DomQuery.select(this.headerSelector)[index];
},
getHeaderCellMeasure : function(index){
return this.getHeaderCell(index).firstChild;
},
getHeaderCellText : function(index){
return this.getHeaderCell(index).firstChild.firstChild;
},
getLockedTable : function(){
return this.lockedBody.dom.firstChild;
},
getBodyTable : function(){
return this.mainBody.dom.firstChild;
},
getLockedRow : function(index){
return this.getLockedTable().rows[index];
},
getRow : function(index){
return this.getBodyTable().rows[index];
},
getRowComposite : function(index){
if(!this.rowEl){
this.rowEl = new Ext.CompositeElementLite();
}
var els = [], lrow, mrow;
if(lrow = this.getLockedRow(index)){
els.push(lrow);
}
if(mrow = this.getRow(index)){
els.push(mrow);
}
this.rowEl.elements = els;
return this.rowEl;
},
getCell : function(rowIndex, colIndex){
var locked = this.cm.getLockedCount();
var source;
if(colIndex < locked){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -