hi, I want to drag items from a grid, and move them to a tree.
I use the tree.onDrag(sid, tid) event.
However, I found that tree.onDrag event is triggered for each sid, thus I cannot judge whether all sids are dragged. In my application, I want to refresh the tree after all items have dragged.
So how could I get all sids when they are dragged into the tree?
Thanks!
a temperory stupid way:
to use jquery.ajax(async:false) to count whether all d-n-ds have finished.
Here is complete sample:
dhtmlx.com/docs/products/dht … ction.html
If you use something other - show the demo.
Darya, thanks for kind reply.
here’s my code:
var dragged_all = new Array(); // 需要移动的页面编号数组
var dragged_success = new Array();// 移动成功的页面编号数组
var dragged_fail = new Array(); // 移动失败的页面编号数组
tree_event();
grid_event();
var tree_event = function(){
tree.attachEvent("onDrag", function(sId,tId){
if(movePage(sId,tId))dragged_success.push(sId);
else dragged_fail.push(sId);
var treeSelectedId = tree_selectedNode(tree);
if (dragged_success.length+dragged_fail.length==dragged_all.length){
// 移动完成
tree_refresh(tree,treeSelectedId);
if(dragged_fail.length!=0)alert("Failed to move:"+dragged_fail.join(","));
dragged_all = new Array();
dragged_fail = new Array();
dragged_success = new Array();
}
return false;
});
tree.attachEvent("onBeforeDrag", function(sId){ // deny to move nodes in the tree
return false;
});
}
var grid_event = function(){
grid.attachEvent("onDragIn", function(){ // deny to drop on items in the grid
return false;
});
grid.attachEvent("onBeforeDrag", function(id){
var selectedRows = grid_selectedRows(grid);
for (var i=0;i<selectedRows.length;i++)dragged_all.push(selectedRows[i]);
return true;
});
}
var movePage = function(sId, tId){
var isSuccess;
$.ajax({
url: "do.php",
async:false,
type:"POST",
data:{
sid:sId,
tid:tId
},
success:function(xml){
var flag = status_flag(xml);
var msg = status_msg(xml);
msgbar_show(msgbar,msg);
switch(flag){
case "error":
isSuccess = false;
alert(msg);
break;
case "warning":
isSuccess = true;
alert(msg);
break;
case "success":
isSuccess = true;
break;
} // end switch
} // end success function
}); // end ajax
return isSuccess;
}