?? dhtmlxtreegrid.js
字號:
if ((this.er)||(this.grid._edtc)) return;
this.er=this.cell.childNodes[0];
this.er=this.er.childNodes[this.er.childNodes.length-1];
this.val=this.er.innerHTML;
this.er.innerHTML="<textarea class='dhx_combo_edit' type='text' style='height:"+(this.cell.offsetHeight-6)+"px; width:100%; border:0px; margin:0px; padding:0px; padding-top:"+(_isFF?1:2)+"px; overflow:hidden; font-size:12px; font-family:Arial;'></textarea>";
if (_isFF) this.er.style.top="1px";
this.er.className+=" editable";
this.er.firstChild.onclick = function(e){(e||event).cancelBubble = true};
this.er.firstChild.value=this.val;
this.er.firstChild.focus();
}
this.detach = function(){
if (!this.er) return;
this.er.innerHTML=this.er.firstChild.value;
this.er.className=this.er.className.replace("editable","");
var z=(this.val==this.er.innerHMTL);
if (_isFF) this.er.style.top="2px";
this.er=null;
return (z);
}
this.getValue = function(){
//alert(this.cell)
var kidsColl = this.cell.childNodes[0].childNodes;
for(var i=0;i<kidsColl.length;i++){
//alert("value: "+kidsColl[i].tagName)
if(kidsColl[i].id=='nodeval')
return kidsColl[i].innerHTML;
}
}
/**
* @desc: set label of treegrid item
* @param: content - new text of label
* @type: private
*/
this.setValueA = function(content){
//alert(this.cell)
var kidsColl = this.cell.childNodes[0].childNodes;
for(var i=0;i<kidsColl.length;i++){
//alert("value: "+kidsColl[i].tagName)
if(kidsColl[i].id=='nodeval')
kidsColl[i].innerHTML=content;
}
}
/**
* @desc: get image of treegrid item
* @param: content - new text of label
* @type: private
*/
this.setImage = function(url){
var z=this.cell.childNodes[0];
var img=z.childNodes[z.childNodes.length-2];
img.src=url;
}
/**
* @desc: set image of treegrid item
* @param: content - new text of label
* @type: private
*/
this.getImage = function(){
var z=this.cell.childNodes[0];
var img=z.childNodes[z.childNodes.length-2];
return img.src;
}
/**
* @desc: sets text representation of cell ( setLabel doesn't triger math calculations as setValue do)
* @param: val - new value
* @type: public
*/
this.setLabel = function(val){
this.setValueA(val);
}
/**
* @desc: set value of grid item
* @param: val - new value (for treegrid this method only used while adding new rows)
* @type: private
*/
this.setValue = function(val){
var valAr = val.split("^");//parent_id^Label^children^im0^im1^im2
this.cell.parentNode.parent_id = valAr[0];
if (!this.grid.kidsXmlFile) valAr[2]=0;
else
this.cell.parentNode._xml_await=(valAr[2]!=0);
this.cell.parentNode.has_kids = valAr[2];
//this.cell.parentNode._xml_wait = true;
var pRow = this.grid.getRowById(valAr[0]);
if(pRow==null){//check detached rows
pRow = this.grid.loadedKidsHash.get("hashOfParents").get(valAr[0])
//if(pRow!=null)
// alert(pRow+"::"+pRow.childNodes.length)
}
var preStr = "";//prenode html
var node = "";//node html (two images and label)
if(pRow!=null){//not zero level
//alert(pRow.cells.length)
var level = (pRow.childNodes[cell._cellIndex].firstChild.childNodes.length-1)-1
for(var i=0;i<level;i++)
preStr += "<span class='space'><img src='"+this.grid.imgURL+"/blanc.gif' height='1px' class='space'></span>"
this.grid.has_kids_inc(pRow,this.cell._cellIndex);
//alert("aga")
if(pRow.expand!=""){
//this.cell.parentNode.style.display = "none"
this.grid.doOnRowAdded = function(row){
if(row.has_kids>0){
var parentsHash = this.loadedKidsHash.get("hashOfParents")
parentsHash.put(row.idd,row)
this.loadedKidsHash.put("hashOfParents",parentsHash)
}
var kidsAr = this.loadedKidsHash.get(row.parent_id)
if(kidsAr==null){
var kidsAr = new Array(0)
}
kidsAr[kidsAr.length] = row.parentNode.removeChild(row);
this.rowsCol._dhx_removeAt(this.rowsCol._dhx_find(row));
this.loadedKidsHash.put(row.parent_id,kidsAr)
}
}else{
this.grid.doOnRowAdded = function(row){}
pRow.childNodes[this.cell._cellIndex].innerHTML = pRow.childNodes[this.cell._cellIndex].innerHTML.replace(/\/plus\.gif/,"/minus.gif")
var kidsAr = this.grid.loadedKidsHash.get(pRow.idd)
if (this._dhkPos)
kidsAr_dhx_insertAt(this._dhkPos,this.cell.parentNode);
else
kidsAr[kidsAr.length] = this.cell.parentNode;
this.grid.loadedKidsHash.put(pRow.idd,kidsAr)
}
}else{//zero level
this.grid.doOnRowAdded = function(row){}
preStr = "";
}
//if has children
if(valAr[2]!="" && valAr[2]!=0)
node+="<img src='"+this.grid.imgURL+"/plus.gif";
else
node+="<img src='"+this.grid.imgURL+"/blank.gif";
node+="' align='absmiddle' onclick='this."+(_isKHTML?"":"parentNode.")+"parentNode.parentNode.parentNode.parentNode.grid.doExpand(this);event.cancelBubble=true;'>";
//this.grid.collapseKids(this.cell.parentNode)
node+="<img src='"+this.grid.imgURL+"/"+valAr[3]+"' align='absmiddle' "+(this.grid._img_height?(" height=\""+this.grid._img_height+"\""):"")+(this.grid._img_width?(" width=\""+this.grid._img_width+"\""):"")+" >";
node+="<span "+(_isFF?"style='position:relative; top:2px;'":"")+"id='nodeval'>"+valAr[1]+"</span>"
/* if (this.grid.multiLine)
this.cell.innerHTML = "<div style=' overflow:hidden; '>"+preStr+""+node+"</div>";
else*/
this.cell.innerHTML = "<div style=' overflow:hidden; white-space : nowrap; height:20px;'>"+preStr+""+node+"</div>";
this.cell._aimage=valAr[3];
if (_isKHTML) this.cell.vAlign="top";
this.cell.parentNode.has_kids=0;
}
}
eXcell_tree.prototype = new eXcell;
/**
* @desc: correct visual representation of tree grid item - initialisation part
* @param: r2 - row object
* @type: private
*/
dhtmlXGridObject.prototype._fixLevel=function(r2){
var pRow=this.getRowById(r2.parent_id);
var trcol=this.cellType._dhx_find("tree");
this.has_kids_inc(pRow,trcol);
if (pRow){
pRow.childNodes[trcol].innerHTML = pRow.childNodes[trcol].innerHTML.replace(/\/plus\.gif/,"/minus.gif")
pRow.expand = "";
}
var preStr="";
if (!pRow) var level=0;
else
var level = (pRow.childNodes[trcol].firstChild.childNodes.length-1)-1;
for(var i=0;i<level;i++)
preStr += "<span class='space'><img src='' height='1' class='space'></span>"
this._fixLevel2(r2,preStr,trcol);
};
/**
* @desc: correct visual representation of tree grid item - recursive part
* @param: r2 - row object
* @param: preStr - string with corrected html
* @param: trcol - index of treeGrid column
* @type: private
*/
dhtmlXGridObject.prototype._fixLevel2=function(r2,preStr,trcol){
var z=r2.childNodes[trcol].firstChild.innerHTML;
z=preStr+z.replace(/<(SPAN)[^>]*(><IMG)[^>]*(><\/SPAN>)/gi,"");
r2.childNodes[trcol].firstChild.innerHTML=z;
var a=this.loadedKidsHash.get(r2.idd);
if (a){
for (var i=0; i<a.length; i++)
this._fixLevel2(a[i],preStr+"<span class='space'><img src='' height='1' class='space'></span>",trcol);
this.loadedKidsHash.put(r2.idd,a);
}
};
/**
* @desc: remove row from treegrid
* @param: node - row object
* @type: private
*/
dhtmlXGridObject.prototype._removeTrGrRow=function(node){
var parent_id = node.parent_id
this.collapseKids(node)
//not sure about purpose of logic below,
//but seems that is works for only one level of inheritance
var tmpAr = this.loadedKidsHash.get(parent_id)
if(tmpAr!=null)
tmpAr._dhx_removeAt(tmpAr._dhx_find(node))
this.loadedKidsHash.remove(node.idd)
//still not enough - must delete all child nodes as well
var noda=node.nextSibling;
this._removeTrGrRowRec(node.idd);
pRow=this.getRowById(parent_id);
if (!pRow) return;
this.has_kids_dec(pRow);
}
/**
* @desc: remove child rows from treegrid
* @param: id - parent row id
* @type: private
*/
dhtmlXGridObject.prototype._removeTrGrRowRec=function(id){
//I think it relative slow
//more than that, it based on
var newa=new Array();
for (var i=0; i<this.rowsCol.length; i++)
if (id==this.rowsCol[i].parent_id)
{
newa[newa.length]=this.rowsCol[i].idd;
this.rowsAr[this.rowsCol[i].idd] = null;
this.rowsCol._dhx_removeAt(i);
i--;
}
if (newa.length)
for (var i=0; i<newa.length; newa++)
this._removeTrGrRowRec(newa[i]);
}
/**
* @desc: count rows inside branch
* @type: private
*/
dhtmlXGridObject.prototype._countBranchLength=function(ind){
if (!this.rowsCol[ind+1]) return 1;
if (this.rowsCol[ind+1].parent_id!=this.rowsCol[ind].idd) return 1;
var count=1; var i=1;
while ((this.rowsCol[ind+count])&&(this.rowsCol[ind+count].parent_id==this.rowsCol[ind].idd)){
count+=this._countBranchLength(ind+count);
}
return count;
}
/**
* @desc: expand row
* @param: rowId - id of row
* @type: public
* @edition: Professional
* @topic: 7
*/
dhtmlXGridObject.prototype.openItem=function(rowId){
var x=this.getRowById(rowId);
if (!x) return;
this._openItem(x);
}
dhtmlXGridObject.prototype._openItem=function(x){
var y=this.getRowById(x.parent_id);
if (y)
if (y.expand!="") this._openItem(y);
this.expandKids(x);
}
dhtmlXGridObject.prototype._addRowClassic=dhtmlXGridObject.prototype.addRow;
/**
* @desc: add new row to treeGrid
* @param: new_id - new row id
* @param: text - array of row label
* @param: ind - position of row (set to null, for using parentId)
* @param: parent_id - id of parent row
* @param: img - img url for new row
* @param: child - child flag [optional]
* @type: public
* @edition: Professional
*/
dhtmlXGridObject.prototype.addRow=function(new_id,text,ind,parent_id,img,child){
var trcol=this.cellType._dhx_find("tree");
var last_row=null;
if ((trcol!=-1)&&((text[trcol]||"").search(/\^/gi)==-1)){
var def=text[trcol];
var d=(parent_id||"0").toString().split(",");
for (var i=0; i<d.length; i++){
text[trcol]=d[i]+"^"+def+"^"+(child?1:0)+"^"+(img||"leaf.gif");
if (d[i]!=0)
if ((!ind)||(ind==0)){
ind=this.getRowIndex(d[i]);
if (this.rowsCol[ind].expand=="") ind+=this._countBranchLength(ind);
}
/* var z=0;
for (var i=0; i<this.rowsCol.length; i++)
z+="<div>"+this.rowsCol[i].idd+"</div>";
document.getElementById("output_a").innerHTML=z;*/
last_row=this._addRowClassic(new_id,text,((!parent_id)&&(!ind)&&(ind!="0"))?window.undefined:ind);
}
return last_row;
}
return this._addRowClassic(new_id,text,ind);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -