Search code examples
jquerydynatreejquery-dynatree

drag and drop from/to dynatree


I'm trying to drag data from a dynatree and drop it to another dynatree. In the documentation an example shows how to move a node in the same tree. Is it possible to move a node and put it in the second dynaTree with all it's option??

first tree has :

    $("#Tree1).dynatree({
 dnd: {
                    onDragStart: function (node) {

                        logMsg("tree.onDragStart(%o)", node);
                        return true;
                    },
});

and the second tree:

 $("#Tree2").dynatree({
        dnd :{
        onDrop: function (node, sourceNode, hitMode, ui, draggable) {
                            logMsg("tree.onDrop(%o, %o, %s)", node, sourceNode, hitMode);
                            sourceNode.move(node, hitMode);
    },


        onDragEnter: function (node, sourceNode) {


                                logMsg("tree.onDragEnter(%o, %o)", node, sourceNode);
                                return true;
                            }
}
        });

thanks in advance


Solution

  • AFAIK, currently dynatree doesn't support move node between different trees. You may, however, copy node from tree1 and add copied node to tree2. After that, you can delete node in tree1. With this approach, you can mimic the behaviour of moving node between trees.

    So instead of using sourceNode.move(node, hitMode), you can use this:

    var copyNode = sourceNode.toDict(true, function (dict) {
        delete dict.key;
    });
    
    node.addChild(copyNode);
    

    Hope this help.