📄 dhtmlxgrid.js
字号:
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;
};
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";
}
}
this.setDelimiter = function(delim){
this.delim = delim;
}
this.setInitWidthsP = function(wp){
this.cellWidthType = "%";
this.initCellWidth = wp.split(this.delim.replace(/px/gi,""));
var el=window;
var self=this;
if(el.addEventListener){
if((_isFF)&&(_FFrv<1.8))
el.addEventListener("resize",function(){
if(!self.entBox)return;
var z=self.entBox.style.width;
self.entBox.style.width="1px";
window.setTimeout(function(){self.entBox.style.width=z;self.setSizes();},10);
},false);
else
el.addEventListener("resize",function(){if(self.setSizes)self.setSizes();},false);
}
else if(el.attachEvent)
el.attachEvent("onresize",function(){
if(self._resize_timer)window.clearTimeout(self._resize_timer);
if(self.setSizes)
self._resize_timer=window.setTimeout(function(){self.setSizes();},500);
});
}
this.setInitWidths = function(wp){
this.cellWidthType = "px";
this.initCellWidth = wp.split(this.delim);
if(_isFF){
for(var i=0;i<this.initCellWidth.length;i++)
if(this.initCellWidth[i]!="*")
this.initCellWidth[i]=parseInt(this.initCellWidth[i])-2;
}
}
this.enableMultiline = function(state){
this.multiLine = convertStringToBoolean(state);
}
this.enableMultiselect = function(state){
this.selMultiRows = convertStringToBoolean(state);
}
this.setImagePath = function(path){
this.imgURL = path;
}
this.changeCursorState = function(ev){
var el = ev.target||ev.srcElement;
if(el.tagName!="TD")
el = this.getFirstParentOfType(el,"TD")
if((el.tagName=="TD")&&(this._drsclmn)&&(!this._drsclmn[el._cellIndex]))return;
if((el.offsetWidth -(ev.offsetX||(parseInt(this.getPosition(el,this.hdrBox))-ev.layerX)*-1))<10){
el.style.cursor = "E-resize";
}else
el.style.cursor = "default";
if(_isOpera)this.hdrBox.scrollLeft = this.objBox.scrollLeft;
}
this.startColResize = function(ev){
this.resized = null;
var el = ev.target||ev.srcElement;
if(el.tagName!="TD")
el = this.getFirstParentOfType(el,"TD")
var x = ev.clientX;
var tabW = this.hdr.offsetWidth;
var startW = parseInt(el.offsetWidth)
if(el.tagName=="TD" && el.style.cursor!="default"){
if((this._drsclmn)&&(!this._drsclmn[el._cellIndex]))return;
this.entBox.onmousemove = function(e){this.grid.doColResize(e||window.event,el,startW,x,tabW)}
document.body.onmouseup = new Function("","document.getElementById('"+this.entBox.id+"').grid.stopColResize()");
}
}
this.stopColResize = function(){
this.entBox.onmousemove = ""; document.body.onmouseup = "";
this.setSizes();
this.doOnScroll(0,1)
if(this.onRSE)this.onRSE(this);
}
this.doColResize = function(ev,el,startW,x,tabW){
el.style.cursor = "E-resize";
this.resized = el;
var fcolW = startW+(ev.clientX-x);
var wtabW = tabW+(ev.clientX-x)
if((this.onRSI)&&(!this.onRSI(el._cellIndex,fcolW,this)))return;
if(el.colSpan>1){
var a_sizes=new Array();
for(var i=0;i<el.colSpan;i++)
a_sizes[i]=Math.round(fcolW*this.hdr.rows[0].childNodes[el._cellIndexS+i].offsetWidth/el.offsetWidth);
for(var i=0;i<el.colSpan;i++)
this._setColumnSizeR(el._cellIndexS+i*1,a_sizes[i]);
}
else
this._setColumnSizeR(el._cellIndex,fcolW);
this.doOnScroll(0,1);
if(_isOpera)this.setSizes();
this.objBuf.childNodes[0].style.width = "";
}
this._setColumnSizeR=function(ind,fcolW){
if(fcolW>(this._drsclmW?(this._drsclmW[ind]||10):10)){
this.obj.firstChild.firstChild.childNodes[ind].style.width = fcolW+"px";
this.hdr.rows[0].childNodes[ind].style.width = fcolW+"px";
if(this.ftr)
this.ftr.rows[0].childNodes[ind].style.width = fcolW+"px";
if(this.cellWidthType=='px'){
this.cellWidthPX[ind]=fcolW;
}else{
var gridWidth = parseInt(this.entBox.offsetWidth);
if(this.objBox.scrollHeight>this.objBox.offsetHeight)
gridWidth-=(this._scrFix||(_isFF?19:16));
var pcWidth = Math.round(fcolW/gridWidth*100)
this.cellWidthPC[ind]=pcWidth;
}
}
}
this.setSortImgState=function(state,ind,direction){
if(!convertStringToBoolean(state)){
this.sortImg.style.display = "none";
return;
}
if(direction=="ASC")
this.sortImg.src = this.imgURL+"sort_asc.gif";
else
this.sortImg.src = this.imgURL+"sort_desc.gif";
this.sortImg.style.display="";
this.fldSorted=this.hdr.rows[0].cells[ind];
this.setSortImgPos(ind);
}
this.setSortImgPos = function(ind,mode){
if(!ind)
var el = this.fldSorted;
else
var el = this.hdr.rows[0].cells[ind];
if(el!=null){
var pos = this.getPosition(el,this.hdrBox)
var wdth = el.offsetWidth;
this.sortImg.style.left = Number(pos[0]+wdth-13)+"px"; this.sortImg.defLeft = parseInt(this.sortImg.style.left)
this.sortImg.style.top = Number(pos[1]+5)+"px";
if((!this.useImagesInHeader)&&(!mode))
this.sortImg.style.display = "inline";
this.sortImg.style.left = this.sortImg.defLeft+"px";}
}
this.setActive = function(fl){
if(arguments.length==0)
var fl = true;
if(fl==true){
globalActiveDHTMLGridObject = this;
this.isActive = true;
}else{
this.isActive = false;
}
};
this._doClick = function(ev){
var selMethod = 0;
var el = this.getFirstParentOfType(_isIE?ev.srcElement:ev.target,"TD");
var fl = true;
if(this.selMultiRows!=false){
if(ev.shiftKey && this.row!=null){
selMethod = 1;
}
if(ev.ctrlKey){
selMethod = 2;
}
}
this.doClick(el,fl,selMethod)
};
this._doContClick=function(ev){
var el = this.getFirstParentOfType(_isIE?ev.srcElement:ev.target,"TD");
if((!el)||(el.parentNode.idd===undefined))return true;
if(ev.button==2){
if((this.onRCL)&&(!this.onRCL(el.parentNode.idd,el._cellIndex,ev)))return;
if(this._ctmndx){
if((this.onBCM)&&(!this.onBCM(el.parentNode.idd,el._cellIndex,this)))return true;
el.contextMenuId=el.parentNode.idd+"_"+el._cellIndex;
el.contextMenu=this._ctmndx;
el.a=this._ctmndx._contextStart;
if(_isIE)
ev.srcElement.oncontextmenu = function(){event.cancelBubble=true;return false;};
el.a(el,ev);
el.a=null;
}
}
return true;
}
this.doClick = function(el,fl,selMethod){
var psid=this.row?this.row.idd:0;
this.setActive(true);
if(!selMethod)
selMethod = 0;
if(this.cell!=null)
this.cell.className = this.cell.className.replace(/cellselected/g,"");
if(el.tagName=="TD" &&(this.rowsCol._dhx_find(this.rowsAr[el.parentNode.idd])!=-1 || this.rowsBuffer[0]._dhx_find(el.parentNode.idd)!=-1)){
if(this.onSSC)var initial=this.getSelectedId();
var prow=this.row;
if(selMethod==0){
this.clearSelection();
}else if(selMethod==1){
var elRowIndex = this.rowsCol._dhx_find(el.parentNode)
var lcRowIndex = this.rowsCol._dhx_find(this.lastClicked)
if(elRowIndex>lcRowIndex){
var strt = lcRowIndex;
var end = elRowIndex;
}else{
var strt = elRowIndex;
var end = lcRowIndex;
}
this.clearSelection();
for(var i=0;i<this.rowsCol.length;i++){
if((i>=strt && i<=end)&&(this.rowsCol[i])&&(!this.rowsCol[i]._sRow)){
if((!this.onBFS)||(this.onBFS(this.rowsCol[i].idd,psid))){
this.rowsCol[i].className+=" rowselected";
this.selectedRows[this.selectedRows.length] = this.rowsCol[i]
}
}
}
}else if(selMethod==2){
if(el.parentNode.className.indexOf("rowselected")!= -1){
el.parentNode.className=el.parentNode.className.replace("rowselected","");
this.selectedRows._dhx_removeAt(this.selectedRows._dhx_find(el.parentNode))
var skipRowSelection = true;
}
}
this.editStop()
this.cell = el;
if((prow == el.parentNode)&&(this._chRRS))
fl=false;
this.row = el.parentNode;
if((!skipRowSelection)&&(!this.row._sRow)){
if((!this.onBFS)||(this.onBFS(this.row.idd,psid))){
this.row.className+= " rowselected"
if(this.selectedRows._dhx_find(this.row)==-1)
this.selectedRows[this.selectedRows.length] = this.row;
}
else this.row=true;
}
if(this.selBasedOn=="cell"){
if(this.cell.parentNode.className.indexOf("rowselected")!=-1)
this.cell.className = this.cell.className.replace(/cellselected/g,"")+" cellselected";
}
if(selMethod!=1)
this.lastClicked = el.parentNode;
var rid = this.row.idd;
var cid = this.cell.cellIndex;
if(fl)setTimeout(function(){self.onRowSelect(rid,cid);},100)
if(this.onSSC){
var afinal=this.getSelectedId();
if(initial!=afinal)this.onSSC(afinal);
}
}
this.isActive = true;
this.moveToVisible(this.cell)
}
this.selectCell = function(r,cInd,fl,preserve,edit){
if(!fl)
fl = false;
if(typeof(r)!="object")
r = this.rowsCol[r]
var c = r.childNodes[cInd];
if(preserve)
this.doClick(c,fl,3)
else
this.doClick(c,fl)
if(edit)this.editCell();
}
this.moveToVisible = function(cell_obj,onlyVScroll){
try{
var distance = cell_obj.offsetLeft+cell_obj.offsetWidth+20;
if(distance>(this.objBox.offsetWidth+this.objBox.scrollLeft)){
var scrollLeft = distance - this.objBox.offsetWidth;
}else if(cell_obj.offsetLeft<this.objBox.scrollLeft){
var scrollLeft = cell_obj.offsetLeft-5
}
if((scrollLeft)&&(!onlyVScroll))
this.objBox.scrollLeft = scrollLeft;
var distance = cell_obj.offsetTop+cell_obj.offsetHeight+20;
if(distance>(this.objBox.offsetHeight+this.objBox.scrollTop)){
var scrollTop = distance - this.objBox.offsetHeight;
}else if(cell_obj.offsetTop<this.objBox.scrollTop){
var scrollTop = cell_obj.offsetTop-5
}
if(scrollTop)
this.objBox.scrollTop = scrollTop;
}catch(er){
}
}
this.editCell = function(){
this.editStop();
if((this.isEditable!=true)||(!this.cell))
return false;
var c = this.cell;
if(c.parentNode._locked)return false;
this.editor = this.cells4(c);
if(this.editor!=null){
if(this.editor.isDisabled()){this.editor=null;return false;}
c.className+=" editable";
if(this.onEditCell(0,this.row.idd,this.cell._cellIndex)!=false){
this._Opera_stop=(new Date).valueOf();
this.editor.edit()
this.onEditCell(1,this.row.idd,this.cell._cellIndex)
}else{ this.editor=null;
}
}
}
this.editStop = function(){
if(_isOpera)
if(this._Opera_stop){
if((this._Opera_stop*1+50)>(new Date).valueOf())return;
this._Opera_stop=null;
}
if(this.editor && this.editor!=null){
this.cell.className=this.cell.className.replace("editable","");
if(this.editor.detach())this.cell.wasChanged = true;
var g=this.editor;
this.editor=null;
var z=this.onEditCell(2,this.row.idd,this.cell._cellIndex,g.getValue(),g.val);
if((typeof(z)=="string")||(typeof(z)=="number"))
g.setValue(z);
else
if(!z)g.setValue(g.val);
}
}
this.doKey = function(ev){
if(!ev)return true;
if((ev.target||ev.srcElement).value!==window.undefined){
var zx=(ev.target||ev.srcElement);
if((!zx.parentNode)||(zx.parentNode.className.indexOf("editable")==-1))
return true;
}
if((globalActiveDHTMLGridObject)&&(this!=globalActiveDHTMLGridObject))
return globalActiveDHTMLGridObject.doKey(ev);
if(this.isActive==false){
return true;
}
if(this._htkebl)return true;
if((this.onKPR)&&(!this.onKPR(ev.keyCode,ev.ctrlKey,ev.shiftKey)))return false;
try{
var type = this.cellType[this.cell._cellIndex]
if(ev.keyCode==13 &&(ev.ctrlKey || ev.shiftKey)){
var rowInd = this.rowsCol._dhx_find(this.row)
if(window.event.ctrlKey && rowInd!=this.rowsCol.length-1){
if(this.row.rowIndex==this.obj._rowslength()-1 && this.dynScroll && this.dynScroll!='false')
this.doDynScroll("dn")
this.selectCell(this.rowsCol[rowInd+1],this.cell._cellIndex,true);
}else if(ev.shiftKey && rowInd!=0){
if(this.row.rowIndex==0 && this.dynScroll && this.dynScroll!='false')
this.doDynScroll("up")
this.selectCell(this.rowsCol[rowInd-1],this.cell._cellIndex,true);
}
_isIE?ev.returnValue=false:ev.preventDefault();
}
if(ev.keyCode==13 && !ev.ctrlKey && !ev.shiftKey){
this.editStop();
this.onEnter(this.row.idd,this.cell._cellIndex);
_isIE?ev.returnValue=false:ev.preventDefault();
}
if(ev.keyCode==9 && !ev.shiftKey){
this.editStop();
var aind=this.cell._cellIndex;
var arow=this.row;
aind++;
if(aind>=this.obj.rows[0].childNodes.length){
aind=0;
arow=this.rowsCol[this.rowsCol._dhx_find(this.row)+1];
if(!arow){
aind=this.row.childNodes.length-1;
return true;}
}
this.selectCell(arow||this.row,aind,((arow)&&(this.row!=arow)));
this.editCell()
_isIE?ev.returnValue=false:ev.preventDefault();
}else if(ev.keyCode==9 && ev.shiftKey){
this.editStop();
var aind=this.cell._cellIndex-1;
var arow=this.row;
if(aind<0)
{
aind=this.obj.rows[0].childNodes.length-1;
arow=this.rowsCol[this.rowsCol._dhx_find(this.row)-1];
if(!arow){aind=0;
return true;}
}
this.selectCell(arow||this.row,aind,((arow)&&(this.row!=arow)));
this.editCell()
_isIE?ev.returnValue=false:ev.preventDefault();
}
if(ev.keyCode==40 || ev.keyCode==38){
if(this.editor && this.editor.combo){
if(ev.keyCode==40)this.editor.shiftNext();
if(ev.keyCode==38)this.editor.shiftPrev();
return false;
}
else{
var rowInd = this.row.rowIndex; if(ev.keyCode==38 && rowInd!=1){
this.selectCell(this.obj._rows(rowInd-2),this.cell._cellIndex,true);
}else if(this.pagingOn && ev.keyCode==38 && rowInd==1 && this.currentPage!=1){
this.changePage(this.currentPage-1)
this.selectCell(this.obj.rows[this.obj.rows.length-1],this.cell._cellIndex,true);
}else if(ev.keyCode==40 && rowInd!=this.rowsCol.length && rowInd!=this.obj.rows.length-1){
this.selectCell(this.obj._rows(rowInd),this.cell._cellIndex,true);
}else if(this.pagingOn && ev.keyCode==40 &&(this.row!=this.rowsCol[this.rowsCol.length-1] || this.rowsBuffer[0].length>0 || !this.recordsNoMore)){
this.changePage(this.currentPage+1)
this.selectCell(this.obj._rows(0),this.cell._cellIndex,true);
}
}
_isIE?ev.returnValue=false:ev.preventDefault();
}
if((ev.keyCode==113)&&(this._f2kE)){
this.editCell();
return false;
}
if(ev.keyCode==32){ var c = this.cell
var ed = cells4(c);
if(ed.changeState()!=false)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -