📄 dhtmlxgrid.js
字号:
*/
this._doOnScroll = function(e,mode){
if (this._onSCRL) this._onSCRL(this.objBox.scrollLeft,this.objBox.scrollTop);
this.doOnScroll(e,mode);
}
/**
* @desc: on scroll grid more inner action
* @type: private
* @topic: 7
*/
this.doOnScroll = function(e,mode){
this.hdrBox.scrollLeft = this.objBox.scrollLeft;
if (this.ftr)
this.ftr.parentNode.scrollLeft = this.objBox.scrollLeft;
this.setSortImgPos(null,true);
if (mode) return;
//load more rows on scroll
if(!this.pagingOn && this.objBox.scrollTop+this.hdrSizeA+this.objBox.offsetHeight>this.objBox.scrollHeight){
if(this._xml_ready && (this.objBox._oldScrollTop!=this.objBox.scrollTop) && this.addRowsFromBuffer()){
this.objBox.scrollTop = this.objBox.scrollHeight - (this.hdrSizeA+1+this.objBox.offsetHeight)
this.objBox._oldScrollTop=this.objBox.scrollTop;
}
}
if (this._dload){
if (this._dLoadTimer) window.clearTimeout(this._dLoadTimer);
this._dLoadTimer=window.setTimeout(function(){ self._askRealRows(); },500);
}
}
/**
* @desc: attach this grid to some object in DOM
* @param: obj - object to attach to
* @type: public
* @topic: 0,7
*/
this.attachToObject = function(obj){
obj.appendChild(this.entBox)
}
/**
* @desc: initialize grid
* @param: fl - if to parse on page xml dataisland
* @type: public
* @topic: 0,7
*/
this.init = function(fl){
this.editStop()
/*TEMPORARY STATES*/
this.lastClicked = null;//row clicked without shift key. used in multiselect only
this.resized = null;//hdr cell that is resized now
this.fldSorted = null;//hdr cell last sorted
this.gridWidth = 0;
this.gridHeight = 0;
//empty grid if it already was initialized
this.cellWidthPX = new Array(0);
this.cellWidthPC = new Array(0);
if(this.hdr.rows.length>0){
this.clearAll(true);
}
if(this.cellType._dhx_find("tree")!=-1){//create hashtable for treegrid
this.loadedKidsHash = new Hashtable();
this.loadedKidsHash.put("hashOfParents",new Hashtable())
}
var hdrRow = this.hdr.insertRow(0);
for(var i=0;i<this.hdrLabels.length;i++){
hdrRow.appendChild(document.createElement("TH"));
hdrRow.childNodes[i]._cellIndex=i;
}
if (_isIE) hdrRow.style.position="absolute";
else hdrRow.style.height='auto';
var hdrRow = this.hdr.insertRow(_isKHTML?2:1);
hdrRow._childIndexes=new Array();
var col_ex=0;
for(var i=0;i<this.hdrLabels.length;i++){
hdrRow._childIndexes[i]=i-col_ex;
if ((this.hdrLabels[i]==this.splitSign)&&(i!=0)){
if (_isKHTML)
hdrRow.insertCell(i-col_ex);
hdrRow.cells[i-col_ex-1].colSpan=(hdrRow.cells[i-col_ex-1].colSpan||1)+1;
hdrRow.childNodes[i-col_ex-1]._cellIndex++;
col_ex++;
hdrRow._childIndexes[i]=i-col_ex;
continue;
}
hdrRow.insertCell(i-col_ex);
hdrRow.childNodes[i-col_ex]._cellIndex=i;
hdrRow.childNodes[i-col_ex]._cellIndexS=i;
this.setHeaderCol(i,this.hdrLabels[i]);
}
if (col_ex==0) hdrRow._childIndexes=null;
this._cCount=this.hdrLabels.length;
if (_isIE) window.setTimeout(function(){ self.setSizes(); },1);
//create virtual top row
if (!this.obj.firstChild)
this.obj.appendChild(document.createElement("TBODY"));
var tar=this.obj.firstChild;
if (!tar.firstChild){
tar.appendChild(document.createElement("TR"));
tar=tar.firstChild;
if (_isIE) tar.style.position="absolute";
else tar.style.height='auto';
for(var i=0;i<this.hdrLabels.length;i++)
tar.appendChild(document.createElement("TH"));
}
this.setColumnIds()
if(this.multiLine==-1)
this.multiLine = true;
if(this.multiLine != true)
this.obj.className+=" row20px";
//
//this.combos = new Array(this.hdrLabels.length);
//set sort image to initial state
this.sortImg.style.position = "absolute";
this.sortImg.style.display = "none";
this.sortImg.src = this.imgURL+"sort_desc.gif";
this.sortImg.defLeft = 0;
//create and kill a row to set initial size
//this.addRow("deletethisrtowafterresize",new Array("",""))
this.entCnt.rows[0].style.display = ''//display header
if(this.noHeader){
this.entCnt.rows[0].style.display = 'none';
}else{
this.noHeader = false
}
this.setSizes();
this.attachHeader();
this.attachHeader(0,0,"_aFoot");
if(fl)
this.parseXML()
this.obj.scrollTop = 0
if (this.dragAndDropOff) this.dragger.addDragLanding(this.entBox,this);
if (this._initDrF) this._initD();
};
/**
* @desc: sets sizes of grid elements
* @type: private
* @topic: 0,7
*/
this.setSizes = function(fl){
if ((!this.noHeader)&&((!this.hdr.rows[0])||(!this.hdrBox.offsetWidth))) return;
if(fl && this.gridWidth==this.entBox.offsetWidth && this.gridHeight==this.entBox.offsetHeight){
return false
}else if(fl){
this.gridWidth = this.entBox.offsetWidth
this.gridHeight = this.entBox.offsetHeight
}
if ((!this.hdrBox.offsetHeight)&&(this.hdrBox.offsetHeight>0))
this.entCnt.rows[0].cells[0].height = this.hdrBox.offsetHeight+"px";
var gridWidth = parseInt(this.entBox.offsetWidth);
var gridHeight = parseInt(this.entBox.offsetHeight);
var _isVSroll=(this.objBox.scrollHeight>this.objBox.offsetHeight);
if (((!this._ahgr)&&(_isVSroll))||((this._ahgrM)&&(this._ahgrM<this.objBox.scrollHeight)))
gridWidth-=(this._scrFix||(_isFF?19:16));
var len = this.hdr.rows[0].cells.length
for(var i=0;i<this._cCount;i++){
if(this.cellWidthType=='px' && this.cellWidthPX.length < len){
this.cellWidthPX[i] = this.initCellWidth[i] - this._wcorr;
}else if(this.cellWidthType=='%' && this.cellWidthPC.length < len){
this.cellWidthPC[i] = this.initCellWidth[i];
}
if(this.cellWidthPC.length!=0){
this.cellWidthPX[i] = parseInt(gridWidth*this.cellWidthPC[i]/100);
}
}
var wcor=this.entBox.offsetWidth-this.entBox.clientWidth;
var summ = 0;
var fcols=new Array();
for(var i=0;i<this._cCount;i++)
if (this.initCellWidth[i]=="*")
fcols[fcols.length]=i;
else
summ += parseInt(this.cellWidthPX[i]);
if (fcols.length){
var ms=Math.floor((gridWidth-summ-1-wcor)/fcols.length);
if (ms<0) ms=1;
for(var i=0;i<fcols.length; i++){
this.cellWidthPX[fcols[i]]=ms-this._wcorr;
summ+=ms;
}
}
this.chngCellWidth();
var summ = 0;
for(var i=0;i<this._cCount;i++)
summ += parseInt(this.cellWidthPX[i])
if (_isOpera) summ-=1;
this.objBuf.style.width = summ + "px";
this.objBuf.childNodes[0].style.width = summ + "px";
//if (_isOpera) this.hdr.style.width = summ + this.cellWidthPX.length*2 + "px";
//set auto page size of dyn scroll
this.doOnScroll(0,1);
//set header part of container visible height to header's height
//this.entCnt.rows[0].cells[0].style.height = this.hdr.offsetHeight;
this.hdr.style.border="0px solid gray"; //FF 1.0 fix
/* if ((_isMacOS)&&(_isFF))
var zheight=20;
else*/
var zheight=this.hdr.offsetHeight+(this._borderFix?this._borderFix:0);
if (this._ahgr)
if (this.objBox.scrollHeight){
if (_isIE)
var z2=this.objBox.scrollHeight;
else
var z2=this.objBox.childNodes[0].scrollHeight;
var scrfix=((this.objBox.offsetWidth<this.objBox.scrollWidth)?(_isFF?20:18):1);
if (this._ahgrMA)
z2=this.entBox.parentNode.offsetHeight-zheight-scrfix;
if (this._ahgrM)
z2=(z2>this._ahgrM?this._ahgrM:z2)*1;
gridHeight=z2+zheight+scrfix;
this.entBox.style.height=gridHeight+"px";
}
var aRow=this.entCnt.rows[1].cells[0].childNodes[0];
if(!this.noHeader)
aRow.style.top = (zheight-this.hdrBox.offsetHeight+(_isFF?0:(1-wcor)))+"px";
//nb 072006:
aRow.style.height = (((gridHeight - zheight-1)<0 && _isIE)?20:(gridHeight - zheight-1))-(this.ftr?this.ftr.offsetHeight:0)+"px";
if (this.ftr) this.entCnt.style.height=this.entBox.offsetHeight-this.ftr.offsetHeight+"px";
if (this._dload)
this._dloadSize=Math.floor(parseInt(this.entBox.style.height)/20)+2; //rough, but will work
};
/**
* @desc: changes cell width
* @param: [ind] - index of row in grid
* @type: private
* @topic: 4,7
*/
this.chngCellWidth = function(){
if ((_isOpera)&&(this.ftr))
this.ftr.width=this.objBox.scrollWidth+"px";
var l=this._cCount;
for(var i=0;i<l;i++){
this.hdr.rows[0].cells[i].style.width = this.cellWidthPX[i]+"px";
this.obj.rows[0].childNodes[i].style.width = this.cellWidthPX[i]+"px";
if (this.ftr)
this.ftr.rows[0].cells[i].style.width = this.cellWidthPX[i]+"px";
}
}
/**
* @desc: set default delimiter
* @param: delim - delimiter as string
* @before_init: 1
* @type: public
* @topic: 0
*/
this.setDelimiter = function(delim){
this.delim = delim;
}
/**
* @desc: set width of columns in percents
* @type: public
* @before_init: 1
* @param: wp - width in percents
* @topic: 0,7
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -