I have 2 trees: source & target tree
Source tree�s structure like this:
Level1:Area-A
Level2: Customer-1 (id:01)
Level2: Customer-5 (id:05)
Level2: Customer-7 (id:07)
Target tree�s structure like this:
Level1:Department-A
Level2: Employee-1 (id:15)
Level3: Customer-1 (id:15_01)
Level3: Customer-7 (id:15_07)
Level2: Employee-2 (id:18)
Level3: Customer-1 (id:18_01)
Level3: Customer-5 (id:18_05)
Level3: Customer-7 (id:18_07)
my requirements:
when drag source tree�s leaf (ex. Customer-5) and drop to target tree�s level 2 (ex. Employee-1), need do check (id:15_05) exist or not. If drag to Employee-2, do check (id:18_05) exist or not
1. if exist : cancel this action
2. if not exist, action successful, and tree-id need setting as above
3. if �enableMultiselection� set to true, how to resolve at this situation?
Thanks a Lot !!
You can try to use onDrag event handler. It allows to block drag-n-drop and gets ids of source and target items as arguments.
The example of the onDrag handler for the target tree:
employeeTree.attachEvent(“onDrag”,function(sid,tid){
var list = this.getSubItems(tid);
leaves = list.split(",");
for(var i =0; i < leaves.length;i++)
if(leaves[i]==tid+""+sid) return false; /* denies drag-n-drop*/
this.changeItemId(sid,tid+""+sid);/sets new id/
return true
})
my code:
dhxTree.attachEvent(“onDrag”,function(sid,tid){
if(tid == sid) return false; /* denies same people*/
var list = this.getSubItems(tid);
if (list.length == 0)
{
this.changeItemId(sid,tid+""+sid);/sets new id/
return true;
}
else
{
leaves = list.split(",");
for(var i =0; i < leaves.length;i++)
if(leaves[i]==tid+""+sid) return false; /* denies drag-n-drop*/
this.changeItemId(sid,tid+"_"+sid);/sets new id/
return true;
}
})
Source tree�s structure like this:
Level1:Area-A
Level2: Customer-A(id:13-11)
Level2: Customer-B(id:13-1)
Level1:Area-B
Level2: Customer-C(id:13-3)
Target tree�s structure like this:
Level1:Type-A
Level2: Customer-A (id: 13-11)
Level2: Customer-C (id: 13-3)
Level1: Type-B
Level2: Customer-B (id: 13-1)
1. drag �Customer-A�, drop �Customer-A�, action cancel, ok
2. drag �Customer-B�, drop �Customer-A�, add in, wrong item-id at line3, 6
Target tree�s structure like this:
/line1/Level1:Type-A
/line2/Level2: Customer-A (id: 13-11)
/line3/Level3: Customer-B (id: 13-1)
/line4/Level2: Customer-C (id: 13-3)
/line5/Level1: Type-B
/line6/Level2: Customer-B (id: 13-11_13-1)
3. drag �Customer-B�, drop �Customer-C�, add in, wrong item-id at line3, 5, 7
Target tree�s structure like this:
/line1/Level1:Type-A
/line2/Level2: Customer-A (id: 13-11)
/line3/Level3: Customer-B (id: 13-3_13-1)
/line4/Level2: Customer-C (id: 13-3)
/line5/Level3: Customer-B (id: 13-1)
/line6/Level1: Type-B
/line7/Level2: Customer-B (id: 13-11_13-1)
seems index have some problems !!
use dhtmlxTree v.2.0 Professional edition build 81009/81107
Hello,
this is a correct behavior as ids in source and target trees are the same.
For example: You drag item with 13-1 from source tree to target, but target already has Customer-B item with id=13-1. So, when you call changeItemId(“13-1”,“13-11_13-1”), the id changes for Customer-B item that is in Type-B branch.
Please, use different ids for tree2 - and the issue will be solved