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

📄 dhtmlxgridcell.js

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

 
function dhtmlXGridCellObject(obj){
 
 this.destructor=function(){
 this.cell.obj=null;
 this.cell=null;
 this.grid=null;
 this.base=null;
 return null;
}
 this.cell = obj;
 
 this.getValue = function(){
 if((this.cell.firstChild)&&(this.cell.firstChild.tagName=="TEXTAREA"))
 return this.cell.firstChild.value;
 else
 return this.cell.innerHTML._dhx_trim();
}

 
 this.getMathValue = function(){
 if(this.cell._val)
 return this.cell._val;
 else return this.getValue();
}
 
 this.getFont = function(){
 arOut = new Array(3);
 if(this.cell.style.fontFamily)
 arOut[0] = this.cell.style.fontFamily
 if(this.cell.style.fontWeight=='bold' || this.cell.parentNode.style.fontWeight=='bold')
 arOut[1] = 'bold';
 if(this.cell.style.fontStyle=='italic' || this.cell.parentNode.style.fontWeight=='italic')
 arOut[1]+= 'italic';
 if(this.cell.style.fontSize)
 arOut[2] = this.cell.style.fontSize
 else
 arOut[2] = "";
 return arOut.join("-")
}
 
 this.getTextColor = function(){
 if(this.cell.style.color)
 return this.cell.style.color
 else
 return "#000000";
}
 
 this.getBgColor = function(){
 if(this.cell.bgColor)
 return this.cell.bgColor
 else
 return "#FFFFFF";
}
 
 this.getHorAlign = function(){
 if(this.cell.style.textAlign)
 return this.cell.style.textAlign;
 else if(this.cell.align)
 return this.cell.align
 else
 return "left";
}
 
 this.getWidth = function(){
 return this.cell.scrollWidth;
}

 
 this.setFont = function(val){
 fntAr = val.split("-");
 this.cell.style.fontFamily = fntAr[0];
 this.cell.style.fontSize = fntAr[fntAr.length-1]
 if(fntAr.length==3){
 if(/bold/.test(fntAr[1]))
 this.cell.style.fontWeight = "bold";
 if(/italic/.test(fntAr[1]))
 this.cell.style.fontStyle = "italic";
 if(/underline/.test(fntAr[1]))
 this.cell.style.textDecoration = "underline";

}

}
 
 this.setTextColor = function(val){
 this.cell.style.color = val;
}
 
 this.setBgColor = function(val){
 if(val=="")
 val = null;
 this.cell.bgColor = val;
}
 
 this.setHorAlign = function(val){
 if(val.length==1){
 if(val=='c')
 this.cell.style.textAlign = 'center'
 else if(val=='l')
 this.cell.style.textAlign = 'left';
 else
 this.cell.style.textAlign = 'right';
}else
 this.cell.style.textAlign = val
}
 
 this.wasChanged = function(){
 if(this.cell.wasChanged)
 return true;
 else
 return false;
}
 
 this.isCheckbox = function(){
 var ch = this.cell.firstChild;
 if(ch && ch.tagName=='INPUT'){
 type = ch.type;
 if(type=='radio' || type=='checkbox')
 return true;
 else
 return false;
}else
 return false;
}
 
 this.isChecked = function(){
 if(this.isCheckbox()){
 return this.cell.firstChild.checked;
}
}
 
 this.isDisabled = function(){
 return this.cell._disabled;
}
 
 this.setChecked = function(fl){
 if(this.isCheckbox()){
 if(fl!='true' && fl!=1)
 fl = false;
 this.cell.firstChild.checked = fl;
}
}
 
 this.setDisabled = function(fl){
 if(fl!='true' && fl!=1)
 fl = false;
 if(this.isCheckbox()){
 this.cell.firstChild.disabled = fl;
 if(this.disabledF)this.disabledF(fl);
}
 this.cell._disabled = fl;
}
}

 
dhtmlXGridCellObject.prototype.setValue = function(val){
 if((typeof(val)!="number")&&(!val || val.toString()._dhx_trim()=="")){
 val=" "
 this.cell._clearCell=true;
}
 this.setCValue(val);
}

dhtmlXGridCellObject.prototype.setCValue = function(val,val2){
 this.cell.innerHTML = val;
 
 
 if(this.grid._onCCH)
 this.grid._onCCH(this.cell.parentNode.idd,this.cell._cellIndex,val2||val);
 
 
}


 
dhtmlXGridCellObject.prototype.setLabel = function(val){
 this.cell.innerHTML = val;
}

 
dhtmlXGridCellObject.prototype.getMath = function(){
 if(this._val)return this.val;
 else
 return this.getValue();
}

 
function eXcell(){
 this.obj = null;
 
 this.val = null;
 
 this.changeState = function(){return false}
 
 this.edit = function(){this.val = this.getValue()}
 
 this.detach = function(){return false}
 
 this.getPosition = function(oNode){
 var oCurrentNode=oNode;
 var iLeft=0;
 var iTop=0;
 while(oCurrentNode.tagName!="BODY"){
 iLeft+=oCurrentNode.offsetLeft;
 iTop+=oCurrentNode.offsetTop;
 oCurrentNode=oCurrentNode.offsetParent;
}
 return new Array(iLeft,iTop);
}
}
eXcell.prototype = new dhtmlXGridCellObject;

 
function eXcell_ed(cell){
 try{
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
}catch(er){}
 this.edit = function(){
 this.cell.atag=((!this.grid.multiLine)&&(_isKHTML||_isMacOS||_isFF))?"INPUT":"TEXTAREA";
 this.val = this.getValue();
 this.obj = document.createElement(this.cell.atag);
 this.obj.style.height =(this.cell.offsetHeight-(_isIE?6:4))+"px";
 this.obj.className="dhx_combo_edit";
 this.obj.wrap = "soft";
 this.obj.style.textAlign = this.cell.align;
 this.obj.onclick = function(e){(e||event).cancelBubble = true}
 this.obj.onmousedown = function(e){(e||event).cancelBubble = true}
 this.obj.value = this.val
 this.cell.innerHTML = "";
 this.cell.appendChild(this.obj);
 if(_isFF){
 this.obj.style.overflow="visible";
 if((this.grid.multiLine)&&(this.obj.offsetHeight>=18)&&(this.obj.offsetHeight<40)){
 this.obj.style.height="36px";
 this.obj.style.overflow="scroll";
}
}
 this.obj.onselectstart=function(e){if(!e)e=event;e.cancelBubble=true;return true;};
 this.obj.focus()
 this.obj.focus()
}
 this.getValue = function(){
 if((this.cell.firstChild)&&((this.cell.atag)&&(this.cell.firstChild.tagName==this.cell.atag)))
 return this.cell.firstChild.value;
 else
 return this.cell.innerHTML.toString()._dhx_trim();
}

 this.detach = function(){
 this.setValue(this.obj.value);
 return this.val!=this.getValue();
}

}
eXcell_ed.prototype = new eXcell;
 
 
 
function eXcell_edn(cell){
 try{
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
}catch(er){}
 this.edit = function(){
 this.val = this.getValue();
 this.obj = document.createElement(_isKHTML?"INPUT":"TEXTAREA");
 this.obj.className="dhx_combo_edit";
 this.obj.style.height =(this.cell.offsetHeight-4)+"px";
 this.obj.wrap = "soft";
 this.obj.style.textAlign = this.cell.align;
 this.obj.onclick = function(e){(e||event).cancelBubble = true}
 this.obj.value = this.val;
 this.cell.innerHTML = "";
 this.cell.appendChild(this.obj);
 this.obj.onselectstart=function(e){if(!e)e=event;e.cancelBubble=true;return true;};
 this.obj.focus()
 this.obj.focus()
}
 this.getValue = function(){
 
 if((this.cell.firstChild)&&(this.cell.firstChild.tagName=="TEXTAREA"))
 return this.cell.firstChild.value;
 else
 return this.grid._aplNFb(this.cell.innerHTML.toString()._dhx_trim(),this.cell._cellIndex);
}

 this.detach = function(){
 var tv=this.obj.value;
 this.setValue(tv);
 return this.val!=this.getValue();
}
}
eXcell_edn.prototype = new eXcell;
eXcell_edn.prototype.setValue = function(val){
 if(!val || val.toString()._dhx_trim()=="")
 val="0"
 this.setCValue(this.grid._aplNF(val,this.cell._cellIndex));
}

 
 

 
function eXcell_ch(cell){
 try{
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
 this.cell.obj = this;
}catch(er){}

 this.disabledF=function(fl){
 if((fl==true)||(fl==1))
 this.cell.innerHTML=this.cell.innerHTML.replace("item_chk0.","item_chk0_dis.").replace("item_chk1.","item_chk1_dis.");
 else
 this.cell.innerHTML=this.cell.innerHTML.replace("item_chk0_dis.","item_chk0.").replace("item_chk1_dis.","item_chk1.");
}

 this.changeState = function(){
 
 if((!this.grid.isEditable)||(this.cell.parentNode._locked))return;
 if(this.grid.onEditCell(0,this.cell.parentNode.idd,this.cell._cellIndex)!=false){
 this.val = this.getValue()
 if(this.val=="1")
 this.setValue("0")
 else
 this.setValue("1")
 
 this.grid.onEditCell(1,this.cell.parentNode.idd,this.cell._cellIndex)
 this.grid.onCheckbox(this.cell.parentNode.idd,this.cell._cellIndex,(this.val!='1'))
}else{
 this.editor=null;
}
}
 this.getValue = function(){
 try{
 return this.cell.chstate.toString();
}catch(er){
 return null;
}
}

 this.isCheckbox = function(){
 return true;
}
 this.isChecked = function(){
 if(this.getValue()=="1")
 return true;
 else
 return false;
}
 this.setChecked = function(fl){
 this.setValue(fl.toString())
}
 this.detach = function(){
 return this.val!=this.getValue();
}
}
eXcell_ch.prototype = new eXcell;
eXcell_ch.prototype.setValue = function(val){
 this.cell.style.verticalAlign = "middle";
 
 if(val){
 val=val.toString()._dhx_trim();
 if((val=="false")||(val=="0"))val="";
}
 if(val){
 val = "1";
 this.cell.chstate = "1";
}else{
 val = "0";
 this.cell.chstate = "0"
}
 var obj = this;
 this.setCValue("<img src='"+this.grid.imgURL+"item_chk"+val+".gif' onclick='this.parentNode.obj.changeState()'>",this.cell.chstate);
}

 
function eXcell_ra(cell){
 this.base = eXcell_ch;
 this.base(cell)
 this.grid = cell.parentNode.grid;

 this.disabledF=function(fl){
 if((fl==true)||(fl==1))
 this.cell.innerHTML=this.cell.innerHTML.replace("radio_chk0.","radio_chk0_dis.").replace("radio_chk1.","radio_chk1_dis.");
 else
 this.cell.innerHTML=this.cell.innerHTML.replace("radio_chk0_dis.","radio_chk0.").replace("radio_chk1_dis.","radio_chk1.");
}

 this.changeState = function(){
 if((!this.grid.isEditable)||(this.cell.parentNode._locked))return;
 if(this.grid.onEditCell(0,this.cell.parentNode.idd,this.cell._cellIndex)!=false){
 this.val = this.getValue()
 if(this.val=="1")
 this.setValue("0")
 else
 this.setValue("1")
 
 this.grid.onEditCell(1,this.cell.parentNode.idd,this.cell._cellIndex)
 if(typeof(this.grid.onCheckbox)=='function')
 this.grid.onCheckbox(this.cell.parentNode.idd,this.cell._cellIndex,(this.val!='1'))
 for(var i=0;i<this.grid.getRowsNum();i++){
 if(this.grid.cells2(i,this.cell._cellIndex).isChecked()&& this.grid.cells2(i,this.cell._cellIndex).cell!=this.cell)
{
 this.grid.cells2(i,this.cell._cellIndex).setValue("0")
 this.grid.onEditCell(1,this.grid.rowsCol[i].idd,this.cell._cellIndex);
}
}
}else{
 this.editor=null;
}
}

}
eXcell_ra.prototype = new eXcell_ch;
eXcell_ra.prototype.setValue = function(val){
 this.cell.style.verticalAlign = "middle";
 if(val){
 val=val.toString()._dhx_trim();
 if((val=="false")||(val=="0"))val="";
}
 if(val){
 val = "1";
 this.cell.chstate = "1";
}else{
 val = "0";
 this.cell.chstate = "0"
}
 var obj = this;
 this.setCValue("<img src='"+this.grid.imgURL+"radio_chk"+val+".gif' onclick='this.parentNode.obj.changeState()'>",this.cell.chstate);
}
 
function eXcell_txt(cell){
 try{
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
}catch(er){}
 this.edit = function(){
 this.val = this.getValue()
 this.obj = document.createElement("TEXTAREA");
 this.obj.className="dhx_textarea";

 this.obj.onclick = function(e){(e||event).cancelBubble = true}
 var arPos = this.grid.getPosition(this.cell);
 if(!this.cell._clearCell)
 this.obj.value = this.cell.innerHTML.replace(/<br[^>]*>/gi,"\n");

 this.obj.style.display = "";
 this.obj.style.textAlign = this.cell.align;
 if(_isFF){
 var z_ff=document.createElement("DIV");
 z_ff.appendChild(this.obj);
 z_ff.style.overflow="auto";
 z_ff.className="dhx_textarea";
 this.obj.style.margin="0px 0px 0px 0px";
 this.obj.style.border="0px";
 this.obj=z_ff;
}
 document.body.appendChild(this.obj);
 this.obj.onkeydown=function(e){
 var ev=(e||event);
 if(ev.keyCode==9){
 globalActiveDHTMLGridObject.entBox.focus();
 globalActiveDHTMLGridObject.doKey({keyCode:ev.keyCode,shiftKey:ev.shiftKey,srcElement:"0"});
 return false;
}
}

 this.obj.style.left = arPos[0]+"px";
 this.obj.style.top = arPos[1]+this.cell.offsetHeight+"px";
 if(this.cell.scrollWidth<200)
 var pw=200;
 else
 var pw=this.cell.scrollWidth;
 this.obj.style.width = pw+(_isFF?18:16)+"px"
 if(_isFF){
 this.obj.firstChild.style.width = parseInt(this.obj.style.width)+"px";
 this.obj.firstChild.style.height = this.obj.offsetHeight-3+"px";
}

 this.obj.focus();
 if(_isFF)this.obj.firstChild.focus();
 else this.obj.focus()

}
 this.detach = function(){

⌨️ 快捷键说明

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