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

📄 dhtmlxdataprocessor.js

📁 dhtmlxGrid是DHTMLX公司的一个非常不错的JAVASCRIPT的网格组件
💻 JS
📖 第 1 页 / 共 2 页
字号:
*     @desc: set function called before server request send ( can be used for including custom client server transport system)
*     @param: func - event handling function
*     @type: public
*     @topic: 0
*     @event: onBeforeUpdate
*     @eventdesc:  Event occured in moment before data sent to server
*     @eventparam: ID of item which need to be updated
*     @eventparam: type of operation
*     @eventreturns: false to block default sending routine
*/
	dataProcessor.prototype.setOnBeforeUpdateHandler=function(func){  if (typeof(func)=="function") this.onBUpd=func; else this.onBUpd=eval(func);  };

	/**
*     @desc: used in combination with setOnBeforeUpdateHandler to create custom client-server transport system
*     @param: sid - id of item before update
*     @param: tid - id of item after up0ate
*     @param: action - action name
*     @type: public
*     @topic: 0
*/
	dataProcessor.prototype.afterUpdateCallback=function(sid,tid,action){
	           this.setUpdated(sid,false);

	               switch (action){
	                   case "insert":
	                       if (tid!=sid){
	                         if (this.obj.mytype=="tree")
	                          this.obj.changeItemId(sid,tid);
	                         else
	                          this.obj.changeRowId(sid,tid);
	                         sid=tid;
	                       }
	                       break;
	                   case "delete":
	                       if (this.obj.mytype=="tree"){
	                        this.obj.deleteItem(sid);
	                        if (this._afterUEvent)
	                            this._afterUEvent(sid,action,tid);
	                        return;
	                        }
	                       else {
			                this.obj.setUserData(sid,"!nativeeditor_status","true_deleted");
	                        this.obj.deleteRow(sid);
						   }
	                       break;

	               }
	               var z=this.obj.getUserData(sid,"!nativeeditor_status",'');
	               if (z!="deleted")
	           this.obj.setUserData(sid,"!nativeeditor_status",'');

	        if (this._lccm) {
	            for(var i=0;i<this.updatedRows.length;i++)
	            	if (this.updatedRows[i]){
	        			this.obj.setUserData(this.updatedRows[i],"!nativeeditor_status","inserted");
	        		    this.setUpdated(this.updatedRows[i],true);
	                    break;
	                    }
			}

	          if (this._afterUEvent)
	              this._afterUEvent(sid,action,tid);
	 };

	/**
	* 	@desc: response from server
	*	@param: xml - XMLLoader object with response XML
	*	@type: private
	*/
	dataProcessor.prototype.afterUpdate = function(that,b,c,d,xml){
		if (that._debug)
			alert("XML status: "+(xml.xmlDoc.responseXML?"correct":"incorrect")+"\nServer response: \n"+xml.xmlDoc.responseText);

		var atag=xml.doXPath("//data/action");
        that._waitMode--;

        for (var i=0; i<atag.length; i++){
           var btag=atag[i];
           var action = btag.getAttribute("type");
           var sid = btag.getAttribute("sid");
           var tid = btag.getAttribute("tid");

		    if ((that._uActions)&&(that._uActions[action])&&(!that._uActions[action](btag))) {}
			else that.afterUpdateCallback(sid,tid,action);
		}
	}

	/**
	* 	@desc: get all row related data
	*	@param: rowId - id of row in question
	*	@type: private
	*/
	dataProcessor.prototype._getRowData = function(rowId,pref){
        if (this.obj.mytype=="tree"){
           var z=this.obj._globalIdStorageFind(rowId);
           var z2=z.parentObject;

           var i=0;
           for (i=0; i<z2.childsCount; i++)
               if (z2.childNodes[i]==z) break;

           var str="tr_id="+escape(z.id);
           str+="&tr_pid="+escape(z2.id);
           str+="&tr_order="+i;
           str+="&tr_text="+escape(z.span.innerHTML);

            z2=(z._userdatalist||"").split(",");
            for (i=0; i<z2.length; i++)
                str+="&"+escape(z2[i])+"="+escape(z.userData["t_"+z2[i]]);

        }
        else
        {
			pref=(pref||"");
           var str=pref+"gr_id="+escape(rowId);
		   if (this.obj.getParentId)
		   str+="&gr_pid="+escape(this.obj.getParentId(rowId));

           var r=this.obj.getRowById(rowId);

           for (var i=0; i<r.childNodes.length; i++)
               {
			   if (this.obj._c_order)
			   		var i_c=this.obj._c_order[i];
			   else
				   	var i_c=i;

			   var c=this.obj.cells(r.idd,i);
			   if (this._endnm)
	               str+="&"+pref+this.obj.getColumnId(i)+"="+escape(c.getValue());
			   else
	               str+="&"+pref+"c"+i_c+"="+escape(c.getValue());
               }
           var data=this.obj.UserData[rowId];
           if (data){
               for (var j=0; j<data.keys.length; j++)
                   str+="&"+pref+data.keys[j]+"="+escape(data.values[j]);
           }
        }
           return str;
	}

	/**
	* 	@desc: specify column which value should be varified before sending to server
	*	@param: ind - column index (0 based)
	*	@param: verifFunction - function (object) which should verify cell value (if not specified, then value will be compared to empty string). Two arguments will be passed into it: value and column name
	*	@type: public;
	*/
	dataProcessor.prototype.setVerificator = function(ind,verifFunction){
		if(verifFunction){
			this.mandatoryFields[ind] = verifFunction;
		}else
			this.mandatoryFields[ind] = true;
	}
	/**
	* 	@desc: remove column from list of those which should be verified
	*	@param: ind - column Index (0 based)
	*	@type: public;
	*/
	dataProcessor.prototype.clearVerificator = function(ind){
		this.mandatoryFields[ind] = false;
	}
	
	/**
	* 	@desc: initializes data-processor
	*	@param: anObj - dhtmlxGrid object to attach this data-processor to
	*	@type: public;
	*/
	dataProcessor.prototype.init = function(anObj){
		this.obj = anObj;
        this.obj.lWin=(new Date()).valueOf()+"-"+Math.random(1000)+"-"+(anObj.entBox||anObj.parentObject).id;
		var self = this;
        if (this.obj.mytype=="tree"){
            if (this.obj.setOnEditHandler)
    		this.obj.setOnEditHandler(function(state,id){
                if (state==3)
                    self.setUpdated(id,true)
                return true;
                });

            this.obj.setDropHandler(function(id,id_2,id_3,tree_1,tree_2){
                    if (tree_1==tree_2)
                self.setUpdated(id,true);
            });
    		this.obj._onrdlh=function(rowId){
                var z=self.obj.getUserData(rowId,"!nativeeditor_status");
    			if (z=="deleted")
    				return true;
    			self.obj.setUserData(rowId,"!nativeeditor_status","deleted");
    			self.setUpdated(rowId,true)
    			self.obj.setItemStyle(rowId,"text-decoration : line-through;");
    			return false;
    		};
    		this.obj._onradh=function(rowId){
    			self.obj.setUserData(rowId,"!nativeeditor_status","inserted");
    			self.setUpdatedTM(rowId,true)
    		};
        }
        else{
      		this.obj.setOnEditCellHandler(function(state,id,index){
      			var cell = self.obj.cells(id,index)
      			if(state==0){

      			}else if(state==1){
					if(cell.isCheckbox()){
      					self.setUpdated(id,true)
      				}
      			}else if(state==2){
      				if(cell.wasChanged()){
						self.setUpdated(id,true)
      				}
      			}
                return true;
      		})
      		this.obj.setOnRowSelectHandler(function(rowId){
      			if(self.updateMode=="row")
      				self.sendData();
                    return true;
      		});
      		this.obj.setOnEnterPressedHandler(function(rowId,celInd){
      			if(self.updateMode=="row")
      				self.sendData();
                    return true;
      		});
      		this.obj.setOnBeforeRowDeletedHandler(function(rowId){
                var z=self.obj.getUserData(rowId,"!nativeeditor_status");
    			if (z=="inserted") {  self.setUpdated(rowId,false);		return true; }
    			if (z=="deleted")  return false;
    			if (z=="true_deleted")  return true;


      			self.obj.setUserData(rowId,"!nativeeditor_status","deleted");
      			self.obj.setRowTextStyle(rowId,"text-decoration : line-through;");
      			self.setUpdated(rowId,true);
      			return false;
      		});
      		this.obj.setOnRowAddedHandler(function(rowId){
      			self.obj.setUserData(rowId,"!nativeeditor_status","inserted");
      			self.setUpdated(rowId,true)
                return true;
      		});

        }
	}


⌨️ 快捷键说明

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