0
votes

I have set up a jstree with drag and drop. For now I am able to drag out a node to a pre defined div. But the node in the tree got removed. How can I drag out a node and let the node stil remain in the tree?

JsTree with dnd plugin, always copy is not working for me. I think it is because I will drop to a div not to another tree.

EDIT: added code

$(function () {
$("#tree").jstree({ 
    "crrm" : {
        "move" : { 
            "check_move" : function (m) { //do not allow messing up the tree!
                    return false;
                },
            "always_copy" : "true"
        }
    },
    "json_data" : {
        "progressive_render" : true,
        "ajax" : { 
            "url" : "lookupInstruments.php", 
            "data": function(n) {
                // the result is fed to the AJAX request 'data' option
                return {"id": n.attr ? n.attr("id") : "root_null_null_-1"};
                }
        }
    },
    "dnd" : {
        "drop_finish" : function (data) { 
            //alert(data.o.attr("ptype"));
            drop(data.o); 
        },
        "drop_check" : function (data) {
            if(data.o.attr("dragable") == "0") {
                return false;
            } else {
                return true; 
            };
        },
    },
    "plugins" : [ "themes", "json_data", "crrm", "dnd" ]
});

});

EDIT 2: SOLVED, hope this helps someone else:

Problem solved, I had to clone the drop object in the drop function.

function drop(dObj) {
var dropObj = dObj.clone();
    ...
}
1
I think it's better to create your own answer than adding the solution to your question ...Radek
I was not allowed to do so for 10h because of lacking points ... I am pretty new to here ...KIC

1 Answers

1
votes

Problem solved. I had to clone the drop object in the drop function.

function drop(dObj) {
var dropObj = dObj.clone();
    ...
}