📄 dhtmlxgridcell.js
字号:
/*
Copyright Scand LLC http://www.scbr.com
To use this component please contact info@scbr.com to obtain license
*/
/**
* @desc: dhtmlxGrid cell object constructor (shouldn't be accesed directly. Use cells and cells2 methods of the grid instead)
* @type: public
* @returns: dhtmlxGrid cell
*/
function dhtmlXGridCellObject(obj){
/**
* @desc: desctructor, clean used memory
* @type: public
*/
this.destructor=function(){
this.cell.obj=null;
this.cell=null;
this.grid=null;
this.base=null;
return null;
}
this.cell = obj;
/**
* @desc: gets Value of cell
* @type: public
*/
this.getValue = function(){
if ((this.cell.firstChild)&&(this.cell.firstChild.tagName=="TEXTAREA"))
return this.cell.firstChild.value;
else
return this.cell.innerHTML._dhx_trim();//innerText;
}
/**
* @desc: gets math formula of cell if any
* @type: public
*/
this.getMathValue = function(){
if (this.cell._val)
return this.cell._val;//innerText;
else return this.getValue();
}
/**
* @desc: determ. font style if it was set
* @returns: font name only if it was set for the cell
* @type: public
*/
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("-")
}
/**
* @desc: determ. cell's text color
* @returns: cell's text color
* @type: public
*/
this.getTextColor = function(){
if(this.cell.style.color)
return this.cell.style.color
else
return "#000000";
}
/**
* @desc: determ. cell's background color
* @returns: cell's background color
* @type: public
*/
this.getBgColor = function(){
if(this.cell.bgColor)
return this.cell.bgColor
else
return "#FFFFFF";
}
/**
* @desc: determines horisontal align od the cell
* @returns: horisontal align of cell content
* @type: public
*/
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";
}
/**
* @desc: gets width of the cell in pixel
* @returns: width of the cell in pixels
* @type: public
*/
this.getWidth = function(){
return this.cell.scrollWidth;
}
/**
* @desc: sets font family to the cell
* @param: val - string in format: Arial-bold(italic,bolditalic,underline)-12px
* @type: public
*/
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";
}
}
/**
* @desc: sets text color to the cell
* @param: val - color value (name or hex)
* @type: public
*/
this.setTextColor = function(val){
this.cell.style.color = val;
}
/**
* @desc: sets background color to the cell
* @param: val - color value (name or hex)
* @type: public
*/
this.setBgColor = function(val){
if(val=="")
val = null;
this.cell.bgColor = val;
}
/**
* @desc: sets horisontal align to the cell
* @param: val - value in single-letter or full format(exmp: r or right)
* @type: public
*/
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
}
/**
* @desc: determines whether cell value was changed
* @returns: true if cell value was changed, otherwise - false
* @type: public
*/
this.wasChanged = function(){
if(this.cell.wasChanged)
return true;
else
return false;
}
/**
* @desc: determines whether first child of the cell is checkbox or radio
* @returns: true if first child of the cell is input element of type radio or checkbox
* @type: public
*/
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;
}
/**
* @desc: determines whether radio or checkbox inside is checked
* @returns: true if first child of the cell is checked
* @type: public
*/
this.isChecked = function(){
if(this.isCheckbox()){
return this.cell.firstChild.checked;
}
}
/**
* @desc: determines whether cell content (radio,checkbox) is disabled
* @returns: true if first child of the cell is disabled
* @type: public
*/
this.isDisabled = function(){
return this.cell._disabled;
}
/**
* @desc: checks checkbox or radion
* @param: fl - true or false
* @type: public
*/
this.setChecked = function(fl){
if(this.isCheckbox()){
if(fl!='true' && fl!=1)
fl = false;
this.cell.firstChild.checked = fl;
}
}
/**
* @desc: disables radio or checkbox
* @param: fl - true or false
* @type: public
*/
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;
}
}
/**
* @desc: sets value to the cell
* @param: val - new value
* @type: public
*/
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;
//#__pro_feature:21092006{
//#on_cell_changed:23102006{
if (this.grid._onCCH)
this.grid._onCCH(this.cell.parentNode.idd,this.cell._cellIndex, val2||val);
//#}
//#}
}
/**
* @desc: sets text representation of cell ( setLabel doesn't triger math calculations as setValue do)
* @param: val - new value
* @type: public
*/
dhtmlXGridCellObject.prototype.setLabel = function(val){
this.cell.innerHTML = val;
}
/**
* @desc: geth math code of ExCell ( actual only for math based exCells )
* @type: public
*/
dhtmlXGridCellObject.prototype.getMath = function(){
if (this._val) return this.val;
else
return this.getValue();
}
/**
* @desc: dhtmlxGrid cell editor constructor (base for all eXcells). Shouldn't be accessed directly
* @returns: dhtmlxGrid cell editor object
* @type: public
*/
function eXcell(){
this.obj = null;//editor
//this.cell = null//cell to get value from
this.val = null;//current value (before edit)
/**
* @desc: occures on space for example
* @type: private
*/
this.changeState = function(){return false}
/**
* @desc: opens editor
* @type: private
*/
this.edit = function(){this.val = this.getValue()}//
/**
* @desc: return value to cell, closes editor
* @returns: if cell's value was changed (true) or not
* @type: private
*/
this.detach = function(){return false}//
/**
* @desc: gets position (left-right) of element
* @param: oNode - element to get position of
* @type: private
* @topic: 8
*/
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;
//simple text editor
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;
//#__pro_feature:21092006{
//#data_format:12052006{
//numeric text editor
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()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -