jQWidgets Forums
jQuery UI Widgets › Forums › General Discussions › Navigation › Tree › DragDrop how to keep the item?
This topic contains 3 replies, has 2 voices, and was last updated by Dimitar 11 years ago.
-
Author
-
Hello,
I use 2 trees one for the recipient items (drop) and one for the source items (drag).
I would like, when I drop an item, to keep it from the source tree.
Is it possible? and if yes how?
Thanks for your help.Hello Stanoweb,
This is possible if you set the first tree’s dragEnd callback as follows (note that it has to return false):
$('#treeA').jqxTree({ allowDrag: true, allowDrop: true, height: '300px', width: '220px', dragEnd: function (dragItem, dropItem, args, dropPosition, tree) { switch (dropPosition) { case "inside": $('#treeB').jqxTree('addTo', dragItem, dropItem); break; case "before": $('#treeB').jqxTree('addBefore', dragItem, dropItem); break; case "after": $('#treeB').jqxTree('addAfter', dragItem, dropItem); break; } return false; } });
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thanks.. I will try it..
What I did was to save the source of the treeA into a temp variable and after adding the node to the treeB, set back the source to the treeA.
Something like this, based on your code :
$(‘#treeA’).jqxTree({ allowDrag: true, allowDrop: true, height: ‘300px’, width: ‘220px’,
dragEnd: function (dragItem, dropItem, args, dropPosition, tree) {
var tempSource= $(‘#treeA’).jqxTree(‘source’)
switch (dropPosition) {
case “inside”:
$(‘#treeB’).jqxTree(‘addTo’, dragItem, dropItem);
break;
case “before”:
$(‘#treeB’).jqxTree(‘addBefore’, dragItem, dropItem);
break;
case “after”:
$(‘#treeB’).jqxTree(‘addAfter’, dragItem, dropItem);
break;
}
$(‘#treeA’).jqxTree({source: tempSource});
return true;
}
});Hello Stanoweb,
You do not need to implement this. Returning false cancels the changes to the first tree anyway.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.