📄 dhtmlxgrid_drag.js
字号:
* @type: private
*/
dhtmlXGridObject.prototype.checkParentLine=function(node,id){
if ((!id)||(!node)) return false;
if (node.idd==id) return true;
else return this.checkParentLine(this.getRowById(node.parent_id),id);
}
/**
* @desc: called when drag moved over landing
* @type: private
*/
dhtmlXGridObject.prototype._dragIn=function(htmlObject,shtmlObject,x,y){
if (!this.dADTempOff) return 0;
var tree=this.isTreeGrid();
if(htmlObject.parentNode==shtmlObject.parentNode)
return 0;
if ((!tree)&&((htmlObject.parentNode.nextSibling) &&(htmlObject.parentNode.nextSibling==shtmlObject.parentNode)))
return 0;
if ((tree)&&((this.checkParentLine(htmlObject.parentNode,shtmlObject.parentNode.idd))))
return 0;
var obj=shtmlObject.parentObject?shtmlObject.parentObject:shtmlObject.parentNode;
if ((this.dragInFunc)&&(!this.dragInFunc(obj.idd||obj.id,htmlObject.parentNode.idd,obj.grid||obj.treeNod,htmlObject.parentNode.grid)))
return 0;
this._setMove(htmlObject,x,y);
if ((tree)&&(htmlObject.parentNode.expand!="")){
this._autoOpenTimer=window.setTimeout(new callerFunction(this._autoOpenItem,this),1000);
this._autoOpenId=htmlObject.parentNode.idd;
}
else
if (this._autoOpenTimer) window.clearTimeout(this._autoOpenTimer);
return htmlObject;
}
/**
* @desc: open item on timeout
* @type: private
*/
dhtmlXGridObject.prototype._autoOpenItem=function(e,gridObject){
gridObject.openItem(gridObject._autoOpenId);
}
/**
* @desc: called on onmouseout event , when drag out landing zone
* @type: private
*/
dhtmlXGridObject.prototype._dragOut=function(htmlObject){
this._clearMove();
if (this._autoOpenTimer) window.clearTimeout(this._autoOpenTimer);
}
/**
* @desc: set visual effect for moving row over landing
* @type: private
*/
dhtmlXGridObject.prototype._setMove=function(htmlObject,x,y){
var a1=getAbsoluteTop(htmlObject);
var a2=getAbsoluteTop(this.objBox);
if (this.dadmode==2)
{
var z=y-a1+this.objBox.scrollTop+(document.body.scrollTop||document.documentElement.scrollTop)-2-htmlObject.offsetHeight/2;
if ((Math.abs(z)-htmlObject.offsetHeight/6)>0)
{
this.dadmodec=1;
//sibbling zone
if (z<0) this.dadmodefix=-1; else this.dadmodefix=1;
}
else this.dadmodec=0;
}
else
this.dadmodec=this.dadmode;
//scroll down
if ( (a1-a2-parseInt(this.objBox.scrollTop))>(parseInt(this.objBox.offsetHeight)-50) )
this.objBox.scrollTop=parseInt(this.objBox.scrollTop)+20;
//scroll top
if ( (a1-a2)<(parseInt(this.objBox.scrollTop)+30) )
this.objBox.scrollTop=parseInt(this.objBox.scrollTop)-20;
if (this.dadmodec){
if (!this._sdrgc) this._createSdrgc();
this._sdrgc.style.display="block";
this._sdrgc.style.top=a1-a2+((this.dadmodefix>=0)?htmlObject.offsetHeight:0)+"px";
}
else{
this._llSelD=htmlObject;
if (htmlObject.parentNode.tagName=="TR")
for (var i=0; i<htmlObject.parentNode.childNodes.length; i++)
{
var z= htmlObject.parentNode.childNodes[i];
z._bgCol=z.style.backgroundColor;
z.style.backgroundColor="#FFCCCC";
}
}
}
/**
* @desc: remove all visual effects
* @type: private
*/
dhtmlXGridObject.prototype._clearMove=function(){
if (this._sdrgc) this._sdrgc.style.display="none";
if ((this._llSelD)&&(this._llSelD.parentNode.tagName=="TR"))
for (var i=0; i<this._llSelD.parentNode.childNodes.length; i++)
this._llSelD.parentNode.childNodes[i].style.backgroundColor=this._llSelD._bgCol;
this._llSelD=null;
}
/**
* @desc: redefine this method in your code to define how grid row values should be displaied while draging
* @param: gridRowId - id of grid row
* @returns: if true, then grid row will be moved to tree, else - copied
* @type: public
* @topic: 7
*/
dhtmlXGridObject.prototype.rowToDragElement=function(gridRowId){
var out=this.cells(gridRowId,0).getValue();
return out;
}
/**
* @desc: copy user data for row
* @type: private
*/
dhtmlXGridObject.prototype._copyUserData = function(c){
var z1 = c.sobj.UserData[c.sid];
var z2 = new Hashtable();
if (z1) {
z2.keys = z2.keys.concat(z1.keys);
z2.values = z2.values.concat(z1.values);
}
c.tobj.UserData[c.tid]=z2;
}
/**
* @desc: move row
* @type: public
* @param: rowId - source row Id
* @param: mode - moving mode (up,down,row_sibling)
* @param: targetId - target row in row_sibling mode
* @param: targetGrid - used for moving between grids (optional)
* @topic: 2
*/
dhtmlXGridObject.prototype.moveRow=function(rowId,mode,targetId,targetGrid){
switch(mode){
case "row_sibling":
this.moveRowTo(rowId,targetId,"move","sibling",this,targetGrid);
break;
case "up":
this.moveRowUp(rowId);
break;
case "down":
this.moveRowDown(rowId);
break;
}
}
/**
* @desc: set function called when drag-and-drop event occured
* @param: aFunc - event handling function
* @type: public
* @topic: 10
* @event: onDrag
* @eventdesc: Event occured after item was dragged and droped on another item, but before item moving processed.
Event also raised while programmatic moving nodes.
* @eventparam: ID of source item
* @eventparam: ID of target item
* @eventparam: source grid object
* @eventparam: target grid object
* @eventreturn: true - confirm drag-and-drop; false - deny drag-and-drop;
*/
dhtmlXGridObject.prototype.setDragHandler=function(func){ if (typeof(func)=="function") this.dragFunc=func; else this.dragFunc=eval(func); }
//#__pro_feature:21092006{
//#drag_adv:21092006{
/**
* @desc: move rows from grid to tree
* @param: tree - object of tree
* @param: targetObject - target node of tree
* @param: beforeNode - anchor node of tree
* @param: itemObject - dragged node
* @param: z2 - flag of recursion
* @type: private
* @edition: Professional
* @topic: 7
*/
dhtmlXGridObject.prototype._nonTrivialNode=function(tree,targetObject,beforeNode,itemObject,z2)
{
if ((tree.dragFunc)&&(!z2))
if (!tree.dragFunc(itemObject.parentNode.idd,targetObject.id,(beforeNode?beforeNode.id:null),this,tree)) return false;
var gridRowId = itemObject.idd;
var treeNodeId = gridRowId+(new Date()).getMilliseconds();
var img=(this.isTreeGrid()?this.getItemImage(gridRowId):"")
var newone=tree._attachChildNode(targetObject,treeNodeId,this.gridToTreeElement(tree,treeNodeId,gridRowId),"",img,img,img,"","",beforeNode);
if (this.loadedKidsHash){
var akids=this.loadedKidsHash.get(gridRowId);
if (akids)
for (var i=0; i<akids.length; i++){
this._nonTrivialNode(tree,newone,0,akids[i],1);
if (!this.dpcpy) i--;
}
}
if (!this.dpcpy) this.deleteRow(gridRowId);
if ((tree.dropFunc)&&(!z2))
tree.dropFunc(treeNodeId,targetObject.id,(beforeNode?beforeNode.id:null),this,tree);
}
/**
* @desc: redefine this method in your code to define how grid row values should be used in tree (using input parameters you can change id of new tree node, set label, set userdata blocks etc.).
* @param: treeObj - object of tree
* @param: treeNodeId - id of node created in tree
* @param: gridRowId - id of grid row
* @returns: if true, then grid row will be moved to tree, else - copied
* @type: public
* @edition: Professional
* @topic: 7
*/
dhtmlXGridObject.prototype.gridToTreeElement = function(treeObj,treeNodeId,gridRowId){
return this.cells(gridRowId,0).getValue();
}
/**
* @desc: redefine this method in your code to define how tree node values should be used in grid (using input parameters you can change id of new row, values for cells, userdata blocks etc.).
* @param: treeObj - object of tree
* @param: treeNodeId - id of node created in tree
* @param: gridRowId - id of grid row
* @returns: if true, then tree node should be moved to grid, else - copied
* @type: public
* @edition: Professional
* @topic: 7
*/
dhtmlXGridObject.prototype.treeToGridElement = function(treeObj,treeNodeId,gridRowId){
var w=new Array();
var z=this.cellType._dhx_find("tree");
if (z==-1) z=0;
for(var i=0;i<this.getColumnCount();i++)
w[w.length]=(i!=z)?(treeObj.getUserData(treeNodeId,this.getColumnId(i))||""):treeObj.getItemText(treeNodeId);
return w;
}
/**
* @desc: move row
* @type: public
* @param: srowId - source row Id
* @param: trowId - target row Id
* @param: mode - move or copy
* @param: dropmode - sibling or child
* @param: sourceGrid - target row in row_sibling mode
* @param: targetGrid - used for moving between grids (optional)
* @edition: Professional
* @topic: 2
*/
dhtmlXGridObject.prototype.moveRowTo=function(srowId,trowId,mode,dropmode,sourceGrid,targetGrid){
var c=new dragContext("grid","grid",mode,dropmode||"sibling",srowId,trowId,sourceGrid||grid,targetGrid||grid);
c.tobj._dragRoutine(c);
c.close();
}
/**
* @desc: set function called after drag-and-drap event occured
* @param: func - event handling function
* @type: public
* @edition: Professional
* @topic: 10
* @event: onDrop
* @eventdesc: Event raised after drag-and-drop processed.
* @eventparam: ID of source item
* @eventparam: ID of target item
* @eventparam: ID of droped item (has sense for mercy drag-n-drop)
* @eventparam: source grid object
* @eventparam: target grid object
*/
dhtmlXGridObject.prototype.setDropHandler=function(func){ if (typeof(func)=="function") this.dropFunc=func; else this.dropFunc=eval(func); };
/**
* @desc: set function called when drag moved over potencial landing
* @param: func - event handling function
* @type: public
* @edition: Professional
* @topic: 10
* @event: onDragIn
* @eventdesc: Event raised if drag moved over potencial landing
* @eventparam: ID of source item
* @eventparam: ID of target item
* @eventparam: source grid object
* @eventparam: target grid object
* @eventreturn: true - allow landing; false - deny landing;
*/
dhtmlXGridObject.prototype.setDragInHandler=function(func){ if (typeof(func)=="function") this.dragInFunc=func; else this.dragInFunc=eval(func); };
/**
* @desc: enable drag without removing (copy instead of move)
* @beforeInit: 1
* @param: mode - 1 - on, 0 - off;
* @type: public
* @edition:Professional
* @topic: 0
*/
dhtmlXGridObject.prototype.enableMercyDrag=function(mode){ this.dpcpy=convertStringToBoolean(mode); };
//#}
//#}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -