Search code examples
javascriptjqueryjstreejstree-dnd

JStree - Only copy children of folder on dnd


Is there an option on the jstree check callback or dnd plug-ins that will only copy the children of a folder over, when a folder is dragged to another tree? I want to copy just the children inside the folder when copying it and not the folder as well. Thanks.


Solution

  • Solved this problem by using an on copy_node event to move each file in the folder up in the tree after the copy and delete the folder after all files are moved out of it

    $('#tree').on("copy_node.jstree", function(e, data){
            if(data.node.icon.indexOf("folder")!=-1){
                var children = data.node.children;
                while(children.length > 0){
                    var node = $('#tree').jstree().get_node(children[0]); 
                    $('#tree').jstree("move_node", node, "#", "before");
                }
                $('#tree').jstree("delete_node", data.node.id);
            }
    }