Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Velmurugant on Jul 28, 2009 03:26
open dhtmlx forum
how to drag leaf level node while dragging parent node in a tree?

Hi,
I am using dhtmlxtree in my applicaion. I need to drag all the childrens only by dragging the parent node. How to do that?
For example, I have a tree
(-)2008
------ january
-- page1
-- page2
----- february
-- page3
---- march
-- page4

(-) 2009
------ january
-- page5
-- page6
----- february
-- page7
---- march
-- page8

Here i need to drag node 2008, but it should drag and drop the leaf childrens only. here page1, page2, page3, page4.
Suppose if I drag the node january , then it should drag and drop page1,page2 only. how to do that? Acually i am getting all the leaf nodes using var totalIDs=holidaytree.getAllSubItems(idFrom).split(",");
Please help me.

thanks,
Velmurugan.
Answer posted by Alex (support) on Jul 28, 2009 03:56

Hello,

you can try to use the following approach:

tree.attachEvent("onDrag",function(sid,tid){
  if(tree.hasChildren(sid)) addItems(sid,tid)
  return false
})

function addItems(sid,tid,sobj,tobj){
  var childs = tree.getAllSubItems(sid).split(",");
  for(var i=0; i< childs.length; i++)
  if(!tree.hasChildren(childs[i])){
  tree.insertNewItem(tid,childs[i],tree.getItemText(childs[i]))
  tree.deleteItem(childs[i])
  }
}


Answer posted by velmurugan on Jul 28, 2009 04:44
Gr8.... thanks alex. It is working fine. I have 1 more doublt. how do i know that from which tree i am dragging? any identification or relationship between tree and its node?
Answer posted by Alex (support) on Jul 28, 2009 04:59

onDrag event handler gets more parameters:

1- source id;
2- target id;
3- before drag id;
4- source tree object
5- target tree object

So, you can use 4th and 5th parameters to identify tree.