EasyUI Forum
May 20, 2024, 09:27:17 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: drag and drop between different trees [Solved]  (Read 5390 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: May 20, 2014, 06:31:31 PM »

I need to be able to drag from one [source] tree into another [destination] tree.

I do NOT want to delete the [source] node, so that I can drag the same source node multiple times into the [destination] tree without deleting the source node.

Is this possible ?



« Last Edit: May 20, 2014, 08:33:14 PM by devnull » Logged

-- Licensed User --
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 20, 2014, 07:05:56 PM »

To prevent from deleting the source node, please return false in the 'onBeforeDrop' event. To continue appending or inserting nodes to the destination tree, you have to write code to achieve this functionality. Please refer to the code below:
Code:
$('#t2').tree({
onBeforeDrop:function(target,source,point){
var sourceTree = $(source.target).closest('ul.tree');
if (sourceTree[0] == this){return true;}
var sourceData = $.extend(true,{},$(sourceTree).tree('getData', source.target));
if (point == 'top'){
$(this).tree('insert', {
before:target,
data:sourceData
})
} else if (point == 'bottom'){
$(this).tree('insert', {
after:target,
data:sourceData
})
} else {
$(this).tree('append', {
parent:target,
data:[sourceData]
})
}
return false;
}
})
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #2 on: May 20, 2014, 08:06:53 PM »

Thanks so much for helping.

Great, that works very well, but I only need to append rather than insert, so the code only uses the append method.

I also need to make sure that dropped elements are unique and can only be added to the parent (level 0) and if dropped onto a child, append to the parent instead, but I will try and figure that one out myself.

 
« Last Edit: May 20, 2014, 08:16:19 PM by devnull » Logged

-- Licensed User --
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!