Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Robin on Dec 03, 2008 08:25
open dhtmlx forum
Drag an item from Tree to TreeGrid as Child. But drag within TreeGrid as sibling

Hi,

I am using Tree & TreeGrid on the same page. I have a requirement where I want to drag an item from Tree to TreeGrid as Child. At the same time I want to drag items within TreeGrid as siblings.

What should be the value of parameter in mygrid.setDragBehavior() function? Please suggest me logic as well if you can.

Thanks in advance.
Answer posted by Support on Dec 04, 2008 02:01
You can't use single static mode, but can change it dynamically. 

 mygrid.attachEvent("onBeforeDrag",function(){
      mygrid.setDragBehavior("sibling");
      return true;
 })
 mytree.attachEvent("onBeforeDrag",function(){
      mygrid.setDragBehavior("child");
      return true;
 })
Answer posted by Robin on Dec 04, 2008 09:07

Hi,

It didnt work. I mean I am not able to invoke the beforedrag event. Following is the code:

mygrid = new dhtmlXGridObject('gridbox3');

mygrid.selMultiRows = false;

mygrid.imgURL = document.getElementById("aDhtmlxImg").src;

mygrid.setHeader(" , ,Name,Version,Status,Author,Modified By,Modified On,Hidden, Hidden1");

mygrid.setInitWidths("25,25,200,50,50,100,100,120,0,0");

mygrid.setColAlign("left,left,left,left,left,left,left,left,left,left");

mygrid.setColTypes("ro,ro,tree,ro,ro,ro,ro,ro,ro,ro");

mygrid.attachEvent("onBeforeSelect",beforeRowSelected);

mygrid.attachEvent("onRowSelect",doOnRowSelected);

mygrid.attachEvent("onBeforeDrag",function(id){

alert("hiiii");

return true;

})

mygrid.attachEvent("onDrag",validateGridDrag);

mygrid.attachEvent("onDrop",validateGridDrop);

//mygrid.setDragBehavior("child");

mygrid.enableDragAndDrop(true);

mygrid.enableTreeCellEdit(false);

mygrid.init();

Suggest Me.

thanks.

 

Answer posted by Support on Dec 04, 2008 10:02
Which version of components you are using?
The onBeforeDrag event available for grid 2.0+ and tree 2.0+

In case of older version, the same effect can be achieved with 
mygrid.setDragBehavior("complex");
mygrid.attachEvent("onDrag",function(){
    if (mygrid.dragContext.source=="tree")
        mygrid.dragContext.dropmode="child";
   else 
        mygrid.dragContext.dropmode="sibling";
   return true;
})
Answer posted by Robin on Dec 04, 2008 10:40
It works. Thanks for the help.