⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhtmlxgrid.js

📁 dhtmlxGrid 是跨浏览器的 JavaScript 表格控制组件(Grid Control)
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*Copyright Scand LLC http://www.scbr.com
This version of Software is free for using in GNU GPL applications. For other use or to get Professional Edition please contact info@scbr.com to obtain license*/ 

 

var globalActiveDHTMLGridObject;
String.prototype._dhx_trim = function(){
 return this.replace(/ /g," ").replace(/(^[ \t]*)|([ \t]*$)/g,"");
}


function dhtmlxArray(ar){return dhtmlXHeir((ar||new Array()),new _dhtmlxArray());};
function _dhtmlxArray(){return this;};
_dhtmlxArray.prototype._dhx_find = function(pattern){
 for(var i=0;i<this.length;i++){
 if(pattern==this[i])
 return i;
}
 return -1;
}
_dhtmlxArray.prototype._dhx_delAt = function(ind){
 if(Number(ind)<0 || this.length==0)
 return false;
 for(var i=ind;i<this.length;i++){
 this[i]=this[i+1];
}
 this.length--;
}
_dhtmlxArray.prototype._dhx_insertAt = function(ind,value){
 this[this.length] = null;
 for(var i=this.length-1;i>=ind;i--){
 this[i] = this[i-1]
}
 this[ind] = value
}
_dhtmlxArray.prototype._dhx_removeAt = function(ind){
 for(var i=ind;i<this.length;i++){
 this[i] = this[i+1]
}
 this.length--;
}
_dhtmlxArray.prototype._dhx_swapItems = function(ind1,ind2){
 var tmp = this[ind1];
 this[ind1] = this[ind2]
 this[ind2] = tmp;
}

 
function dhtmlXGridObject(id){
 if(_isIE)try{document.execCommand("BackgroundImageCache",false,true);}catch(e){}
 if(id){
 if(typeof(id)=='object'){
 this.entBox = id
 this.entBox.id = "cgrid2_"+(new Date()).getTime();
}else
 this.entBox = document.getElementById(id);
}else{
 this.entBox = document.createElement("DIV");
 this.entBox.id = "cgrid2_"+(new Date()).getTime();
}



 this._tttag=this._tttag||"rows";
 this._cttag=this._cttag||"cell";
 this._rttag=this._rttag||"row";

 var self = this;

 this._wcorr=0;
 this.nm = this.entBox.nm || "grid";
 this.cell = null;
 this.row = null;
 this.editor=null;
 this._f2kE=true;this._dclE=true;
 this.combos=new Array(0);
 this.defVal=new Array(0);
 this.rowsAr = new Array(0); this.rowsCol = new dhtmlxArray(0);  this._maskArr=new Array(0);
 this.selectedRows = new dhtmlxArray(0); this.rowsBuffer = new Array(new dhtmlxArray(0),new dhtmlxArray(0)); this.loadedKidsHash = null; this.UserData = new Array(0)
 

 this.styleSheet = document.styleSheets;
 this.entBox.className = "gridbox";
 this.entBox.style.width = this.entBox.getAttribute("width")||(window.getComputedStyle?window.getComputedStyle(this.entBox,null)["width"]:(this.entBox.currentStyle?this.entBox.currentStyle["width"]:0))|| "100%";
 this.entBox.style.height = this.entBox.getAttribute("height")||(window.getComputedStyle?window.getComputedStyle(this.entBox,null)["height"]:(this.entBox.currentStyle?this.entBox.currentStyle["height"]:0))|| "100%";
  this.entBox.style.cursor = 'default';
 this.entBox.onselectstart = function(){return false}; this.obj = document.createElement("TABLE");
 this.obj.cellSpacing = 0;
 this.obj.cellPadding = 0;
 this.obj.style.width = "100%"; this.obj.style.tableLayout = "fixed";
 this.obj.className = "obj";

 this.obj._rows=function(i){return this.rows[i+1];}
 this.obj._rowslength=function(){return this.rows.length-1;}

 this.hdr = document.createElement("TABLE");
 this.hdr.style.border="1px solid gray"; this.hdr.cellSpacing = 0;
 this.hdr.cellPadding = 0;
 if((!_isOpera)||(_OperaRv>=9))
 this.hdr.style.tableLayout = "fixed";
 this.hdr.className = "hdr";
 this.hdr.width = "100%";

 this.xHdr = document.createElement("TABLE");
 this.xHdr.cellPadding = 0;
 this.xHdr.cellSpacing = 0;
 var r = this.xHdr.insertRow(0)
 var c = r.insertCell(0);
 r.insertCell(1).innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
 c.appendChild(this.hdr)
 this.objBuf = document.createElement("DIV");
 this.objBuf.appendChild(this.obj);
 this.entCnt = document.createElement("TABLE");
 this.entCnt.insertRow(0).insertCell(0)
 this.entCnt.insertRow(1).insertCell(0);



 this.entCnt.cellPadding = 0;
 this.entCnt.cellSpacing = 0;
 this.entCnt.width = "100%";
 this.entCnt.height = "100%";

 this.entCnt.style.tableLayout = "fixed";

 this.objBox = document.createElement("DIV");
 this.objBox.style.width = "100%";
 this.objBox.style.height = this.entBox.style.height;
 this.objBox.style.overflow = "auto";
 this.objBox.style.position = "relative";
 this.objBox.appendChild(this.objBuf);
 this.objBox.className = "objbox";


 this.hdrBox = document.createElement("DIV");
 this.hdrBox.style.width = "100%"
 if(((_isOpera)&&(_OperaRv<9)))
 this.hdrSizeA=25;else this.hdrSizeA=100;



 this.hdrBox.style.height=this.hdrSizeA+"px";
 if(_isIE)
 this.hdrBox.style.overflowX="hidden";
 else
 this.hdrBox.style.overflow = "hidden";

 this.hdrBox.style.position = "relative";
 this.hdrBox.appendChild(this.xHdr);



 this.preloadImagesAr = new Array(0)

 this.sortImg = document.createElement("IMG")
 this.sortImg.style.display = "none";
 this.hdrBox.insertBefore(this.sortImg,this.xHdr)
 this.entCnt.rows[0].cells[0].vAlign="top";
 this.entCnt.rows[0].cells[0].appendChild(this.hdrBox);
 this.entCnt.rows[1].cells[0].appendChild(this.objBox);


 this.entBox.appendChild(this.entCnt);
  this.entBox.grid = this;
 this.objBox.grid = this;
 this.hdrBox.grid = this;
 this.obj.grid = this;
 this.hdr.grid = this;
 
 this.cellWidthPX = new Array(0); this.cellWidthPC = new Array(0); this.cellWidthType = this.entBox.cellwidthtype || "px";
 this.delim = this.entBox.delimiter || ",";
 this._csvDelim = ",";

 this.hdrLabels =(this.entBox.hdrlabels || "").split(",");
 this.columnIds =(this.entBox.columnids || "").split(",");
 this.columnColor =(this.entBox.columncolor || "").split(",");
 this.cellType = dhtmlxArray((this.entBox.cellstype || "").split(","));
 this.cellAlign =(this.entBox.cellsalign || "").split(",");
 this.initCellWidth =(this.entBox.cellswidth || "").split(",");
 this.fldSort =(this.entBox.fieldstosort || "").split(",")
 this.imgURL = this.entBox.imagesurl || "gridCfx/";
 this.isActive = false; this.isEditable = true;
 this.raNoState = this.entBox.ranostate || null;
 this.chNoState = this.entBox.chnostate || null;
 this.selBasedOn =(this.entBox.selbasedon || "cell").toLowerCase()
 this.selMultiRows = this.entBox.selmultirows || false;
 this.multiLine = this.entBox.multiline || false;
 this.noHeader = this.entBox.noheader || false;
 this.dynScroll = this.entBox.dynscroll || false; this.dynScrollPageSize = 0; this.dynScrollPos = 0; this.xmlFileUrl = this.entBox.xmlfileurl || "";
 this.recordsNoMore = this.entBox.infinitloading || true;; this.useImagesInHeader = false; this.pagingOn = false;  this.rowsBufferOutSize = 0; 
 this.onCheckbox=this.onEnter=this.onRowSelect=this.onEditCell = function(){return true;};
 dhtmlxEvent(window,"unload",function(){try{self.destructor();}catch(e){}});

 
 
 this.loadXML = function(url,afterCall){
 if(this._dload){this._dload=url;this._askRealRows();return true;};
 if(this._xmlaR)this.setXMLAutoLoading(url);


 if(url.indexOf("?")!=-1)
 var s = "&";
 else
 var s = "?";
 var obj = this;
 if(this.onXLS)this.onXLS(this);

 if(afterCall)this.xmlLoader.waitCall=afterCall;
 this.xmlLoader.loadXML(url+""+s+"rowsLoaded="+this.getRowsNum()+"&lastid="+this.getRowId(this.getRowsNum()-1)+"&sn="+Date.parse(new Date()));
   }

 
 this.setSkin = function(name){
 this.entBox.className = "gridbox gridbox_"+name;
 switch(name){
 case "xp": this._srdh=22;break;
 case "gray": this._borderFix=(_isIE?1:0);break;
}
}


 
 this.doLoadDetails = function(obj){
 var root = self.xmlLoader.getXMLTopNode(self._tttag)
 if(root.tagName!="DIV")
 if(!self.xmlLoader.xmlDoc.nodeName){
 self.parseXML(self.xmlLoader.xmlDoc.responseXML)
}else{
 self.parseXML(self.xmlLoader.xmlDoc)
}
  if(self.pagingOn)
 self.createPagingBlock()
}
 this.xmlLoader = new dtmlXMLLoaderObject(this.doLoadDetails,window,true,this.no_cashe);
 if(_isIE)this.preventIECashing(true);
 this.dragger=new dhtmlDragAndDropObject();

 
 
 this._doOnScroll = function(e,mode){
 if(this._onSCRL)this._onSCRL(this.objBox.scrollLeft,this.objBox.scrollTop);
 this.doOnScroll(e,mode);
}
 
 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;
 
  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);
}

}
 
 this.attachToObject = function(obj){
 obj.appendChild(this.entBox)

}
 
 this.init = function(fl){

 this.editStop()
 
 this.lastClicked = null; this.resized = null; this.fldSorted = null; this.gridWidth = 0;
 this.gridHeight = 0;
  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){ 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);

  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.sortImg.style.position = "absolute";
 this.sortImg.style.display = "none";
 this.sortImg.src = this.imgURL+"sort_desc.gif";
 this.sortImg.defLeft = 0;
   this.entCnt.rows[0].style.display = ''  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();

};
 
 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";
   this.doOnScroll(0,1);

  
 this.hdr.style.border="0px solid gray"; 
 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";

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -