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

📄 dhtmlxtreegrid.js

📁 dhtmlxGrid 是跨浏览器的 JavaScript 表格控制组件(Grid Control)
💻 JS
📖 第 1 页 / 共 2 页
字号:
/*
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
*/ 

/**
*	@desc: switch current row state (collapse/expand) tree grid row
*	@param: obj - row object
*	@type: private
*/
dhtmlXGridObject.prototype.doExpand=function(obj){  
    this.editStop();
	var row = obj.parentNode.parentNode.parentNode;
	var tbl = this.obj;
	var disp = "";
	if(obj.src.indexOf("plus")!=-1){
		this.expandKids(row,true)
	}else{
        if (!row._closeable)
    		this.collapseKids(row)
	}
}




/**
*	@desc: close row of treegrid (removes kids from dom)
*	@param: curRow - row to process kids of
*	@param: kidsAr - array where to store child rows. if exists, then rows added to it
*	@param: start - row to start processing from (only if 3 arguments)
*	@type: private
*/
dhtmlXGridObject.prototype.collapseKids=function(curRow,kidsAr,start){
    if (curRow.expand!="") return;
    if ((this._spnFH)&&(!this._spnFH(curRow.idd,1))) return;

	if(!start)
		start = curRow.rowIndex;

	if(!kidsAr){
		kidsAr = new Array(0)
		curRow.expand="none"
		treeCell = curRow.childNodes[this.cellType._dhx_find("tree")]
		treeCell.innerHTML = treeCell.innerHTML.replace(/\/minus\.gif/,"/plus.gif")
	}
	for(var i=start;i<this.obj._rowslength();i++){
		var row = this.obj._rows(i);
		if(row.parent_id==curRow.idd){
			if(row.expand=="")
				var add_fl = true
			else
				var add_fl = false
			kidsAr[kidsAr.length] = row.parentNode.removeChild(row);

			this.rowsCol._dhx_removeAt(i)
			if(add_fl)
				this.collapseKids(row,null,i)
			i--;
		}
	}

    if (this._ahgr) this.setSizes();



	this.loadedKidsHash.put(curRow.idd,kidsAr)
	if(arguments.length==1){
        if (this._epnFH) this._epnFH(curRow.idd,-1);
        }

	return kidsAr;
}


/**
*	@desc: change parent of row, correct kids collections
*	@param: r2 - moved row
*	@param: r1 - new parent row
*	@type: private
*/
        dhtmlXGridObject.prototype._changeParent=function(r2,r1){
            if (!r1){
               r2.parent_id=0;
                return;
            }
            if (r2.parent_id==r1.idd){
                var a=this.loadedKidsHash.get(r1.idd);
                var z=a._dhx_find(r2);
                a._dhx_removeAt(z);
                if (this._dhkPos){
                    if (this._dhkPos>z) this._dhkPos--;
                    a._dhx_insertAt(this._dhkPos,r2);
                }
                this.loadedKidsHash.put(r1.idd,a);
/*                for (var i=0; i<a.length; i++)
                    alert(a[i].idd);*/
                return;
            }
            var a=this.loadedKidsHash.get(r2.parent_id);
            var b=this.loadedKidsHash.get(r1.idd);
            if (!b) b=new Array();
            if (a){
                a._dhx_removeAt(a._dhx_find(r2));
                this.loadedKidsHash.put(r2.parent_id,a);
                }
            if (this._dhkPos){
                b._dhx_insertAt(this._dhkPos,r2);
                }
            else
                b._dhx_insertAt(0,r2);
            this.loadedKidsHash.put(r1.idd,b);

            r2.parent_id=r1.idd;
        }


/**
*	@desc: change parent of row, correct kids collections
*	@param: curRow - row to process
*	@type: private
*/
dhtmlXGridObject.prototype.expandKids=function(curRow){
    if ((curRow.has_kids==0)&&(!curRow._xml_await)) return;
    if (curRow.expand=="") return;
    if (!curRow._loading)
        if ((this._spnFH)&&(!this._spnFH(curRow.idd,-1))) return;

	var start = this.getRowIndex(curRow.idd)+1;
	var kidsAr = this.loadedKidsHash.get(curRow.idd);

	if(kidsAr!=null){
        curRow._loading=false;
    	curRow.expand = "";
    	treeCell = curRow.childNodes[this.cellType._dhx_find("tree")];
	    treeCell.innerHTML = treeCell.innerHTML.replace(/\/(plus|blank)\.gif/,"/minus.gif");

		for(var i=0;i<kidsAr.length;i++){
			//alert(kidsAr[i].outerHTML)
			var row = (!_isKHTML)?this.obj.childNodes[0].appendChild(kidsAr[i]):this.obj.appendChild(kidsAr[i]);

			if (this.obj._rows(start) && this.obj._rows(start)!=row )
                this.obj._rows(start).parentNode.insertBefore(row,this.obj._rows(start));
            //next line commented, because record already exists in  rowsCol array
			this.rowsCol._dhx_insertAt(start,row)
			start++;
		}
	    if(this.fldSorted!=null){
    		this.sortTreeRows(this._ls_col, this._ls_type, this._ls_order);
        if (this._epnFH) this._epnFH(curRow.idd,1);
    	}
	}else{
        if (curRow._xml_await){
		if(this.kidsXmlFile.indexOf("?")!=-1)
			var s = "&";
		else
			var s = "?";
        curRow._loading=true;
		this.loadXML(this.kidsXmlFile+""+s+"id="+curRow.idd);
        }
	}
    if ((this._ahgr)&&(!this._startXMLLoading)) this.setSizes();
    if (!curRow._loading)
    if (this._epnFH) this._epnFH(curRow.idd,1);
}

dhtmlXGridObject.prototype.kidsXmlFile = "";



/**
*	@desc: sorts treegrid by specified column
*	@param: col - column index
*	@param:	type - str.int.date
*	@param: order - asc.desc
*	@type: public
*   @edition: Professional
*	@topic: 2,3,5,9
*/
dhtmlXGridObject.prototype.sortTreeRows = function(col,type,order){
                    this._ls_col=col;
                    this._ls_type=type;
                    this._ls_order=order;

					var byParentHash = new Hashtable();
					for(var i=0;i<this.obj._rowslength();i++){
						if(byParentHash.get(this.obj._rows(i).parent_id)==null)
							byParentHash.put(this.obj._rows(i).parent_id,new Array());
					}
					for(var i=0;i<this.obj._rowslength();i++){
						var tmpAr = byParentHash.get(this.obj._rows(i).parent_id);
						tmpAr[tmpAr.length] = this.obj._rows(i).idd//i
						byParentHash.put(this.obj._rows(i).parent_id,tmpAr);
					}


					var keysAr = byParentHash.keys;
					for(var j=0;j<keysAr.length;j++){
						var tmpAr = byParentHash.get(keysAr[j]);
						var ar = new Array();
						for(var i=0;i<tmpAr.length;i++){
							ar[i] = new Array();

							var c = this.getRowById(tmpAr[i]).cells[col];
							eval("var ed = new eXcell_"+this.cellType[col]+"(c)");
							if(type=='int'){
								if(ed.getValue().toString()._dhx_trim()=="")
									ar[i][0] = -999999999
								else
									ar[i][0] = parseInt(ed.getValue().toString());
							}else
								ar[i][0] = ed.getValue().toString();

							ar[i][1] = this.getRowById(tmpAr[i])//obj.rows[tmpAr[i]];
                            if ((i!=0)&&(ar[i][0]!=ar[i-1][0])) ar._sort_me=true;
						}
                        // debugger;
                        if (ar._sort_me)
                        {
    					if(type=='str')
							ar.sort(function(a,b){return (a[0]<b[0]?-1:(a[0]==b[0]?0:1))})

						if(type=='int')
							ar.sort(function(a,b){return (a[0]<b[0]?-1:(a[0]==b[0]?0:1))})

						if(type=='date'){
							try{
								ar.sort(function(a,b){return Date.parse(new Date(a[0]))-Date.parse(new Date(b[0]))})
							}catch(er){
								alert('Incompatible date format.Sorted as string')
							    ar.sort(function(a,b){return (a[0]<b[0]?-1:(a[0]==b[0]?0:1))})
							}
						}
                        }


            //  debugger;

                if (!_isKHTML){
                    var tb = this.obj.childNodes[0];
                    var z=this.getRowById(keysAr[j]);
                    if (z) z=z.rowIndex+1;
                    }
                else{
                    var tb = this.obj._rows(0).parentNode;
                    var z=-1;
                    for (var zkk=0; zkk<this.obj._rowslength(); zkk++)
                        if (this.obj._rows(zkk).idd==keysAr[j])
                            { z=zkk+1; break; }
                    }



                if (z<1) 	var parentInd=0;
                else       	var parentInd=z-1;


						if ((order!='asc')&&(ar._sort_me))
							for(var i=0;i<ar.length;i++)                        {
                                if (tb.moveRow)
    								tb.moveRow(ar[i][1].rowIndex,parentInd+1)
                                else
                                   if (this.obj._rows(parentInd))
                                       {
                                       if (ar[i][1]!=this.obj._rows(parentInd))
                                       tb.insertBefore(ar[i][1],this.obj._rows(parentInd));
                                       }
                                   else
                                       tb.appendChild(ar[i][1]);                }

						else
						   	for(var i=ar.length-1;i>=0;i--)                      {
                                if (tb.moveRow)
        						   tb.moveRow(ar[i][1].rowIndex,parentInd+1) ;
                                else
                                   if (this.obj._rows(parentInd))
                                       {
                                       if (ar[i][1]!=this.obj._rows(parentInd))
                                       tb.insertBefore(ar[i][1],this.obj._rows(parentInd));
                                       }
                                   else
                                       tb.appendChild(ar[i][1]);                  }
					}


                    this.rowsCol=new Array();
                    for (var i=0; i<this.obj._rowslength(); i++)
                        this.rowsCol[i]=this.obj._rows(i);

					   //	this.setSizes();

					}

/**
*	@desc: correct kids collection after adding new row
*	@param: pRow - parent row
*	@type: private
*/
dhtmlXGridObject.prototype.has_kids_dec=function(pRow){
            if (!pRow) return;
            pRow.has_kids--;
            if (pRow.has_kids==0){
                    pRow.expand=null;
                	var treeCell = pRow.childNodes[this.cellType._dhx_find("tree")];
  		        	treeCell.innerHTML = treeCell.innerHTML.replace(/\/plus|minus\.gif/,"/blank.gif")
               }
            /*
            if (pRow._sumArr)
                for (var i=0; i<pRow.childNodes.length; i++)
                    if  (pRow.childNodes[i]._sumArr)
                        this.cells3(pRow,i).setValueA(this._calcSCL(i));*/
      }

/**
*	@desc: correct kids collection after removing new row
*	@param: pRow - parent row
*	@param: treeCell - index of tree column
*	@type: private
*/
dhtmlXGridObject.prototype.has_kids_inc=function(pRow,treeCell){
                if (!pRow) return;
                if ((!pRow.has_kids)||(pRow.has_kids==0)){
                    pRow.has_kids=1;
                    pRow.expand="no";
  			        pRow.childNodes[treeCell].innerHTML = pRow.childNodes[treeCell].innerHTML.replace(/\/blank\.gif/,"/plus.gif")
                    }
                else{
                    pRow.has_kids++;
                    }
//                alert(pRow.idd+"-"+pRow.has_kids);
        }



/**
*	@desc: TreeGrid cell constructor
*	@param: cell - cell object
*	@type: private
*/
function eXcell_tree(cell){
	try{
		this.cell = cell;
		this.grid = this.cell.parentNode.grid;
	}catch(er){}
	this.edit = function(){

⌨️ 快捷键说明

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