'dnd': { 'drag_check': function(data) { return (data.attr('class') == 'dragToJsTree') ? true : false; } }, "plugins": [ "dnd", "search", "state", "types", "wholerow", "ui", "crrm", "sort" ]
$(function () { $('#tree').jstree({ core : { 'check_callback' : true }, { id : 1, text: $(this).text() }
Please copy & paste the following exactly (you do not need to handle dnd_stop and dnd_move manually):
$('#tree').jstree({
'core': {
'check_callback' : true
},
'plugins': [ 'dnd' ]
}).on('copy_node.jstree', function (e, data) {
console.log(data.node);
});
$('.drag')
.on('mousedown', function (e) {
return $.vakata.dnd.start(e, { 'jstree' : true, 'obj' : $(this), 'nodes' : [{ id : true, text: $(this).text(), 'data' : {'more':'stuff'} }] }, '<div id="jstree-dnd" class="jstree-default"><i class="jstree-icon jstree-er"></i>' + $(this).text() + '</div>');
});
<div class="drag" style="padding:5px; display:inline-block; background:red; border-radius:4px;">Drag me</div> <div id="tree" class="jstree jstree-default"></div> <div class="drop" style="min-height:200px; min-width:200px; background:lime; border-radius:10px;">Drop here</div>
<script> $('#tree').jstree({ 'core': { 'check_callback': true }, 'plugins': ['dnd'] }).on('copy_node.jstree', function(e, data) {<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> <link rel="stylesheet" type="text/css" href="../scripts/jstree/themes/default/style.min.css" /> <link rel="stylesheet" type="text/css" href="../scripts/css/smoothness/jquery-ui-1.10.4.custom.min.css" /> <link rel="stylesheet" type="text/css" href="../scripts/jstree/themes/default/style.min.css" />
<script type="text/javascript" src="../scripts/jstree/libs/jquery.js"></script> <script type="text/javascript" src="../scripts/jstree/jstree.min.js"></script> <script type="text/javascript" src="../scripts/jstree/libs/require.js"></script> <script type="text/javascript" src="../scripts/jstree/libs/jquery.ui.touch.js"></script> <script> function load() { $('#tree').jstree({ 'core': { 'check_callback': true }, 'plugins': ['dnd'] }).on('copy_node.jstree', function(e, data) { console.log(data.node);
});
$('.drag') .on('mousedown', function(e) { return $.vakata.dnd.start(e, {'jstree': true, 'obj': $(this), 'nodes': [{id: true, text: $(this).text(), 'data': {'more': 'stuff'}}]}, '<div id="jstree-dnd" class="jstree-default"><i class="jstree-icon jstree-er"></i>' + $(this).text() + '</div>'); }); } </script> </head> <body onload="load()">
<div class="drag" style="padding:5px; display:inline-block; background:red; border-radius:4px;">Drag me</div> <div id="tree" class="jstree jstree-default"></div> <div class="drop" style="min-height:200px; min-width:200px; background:lime; border-radius:10px;">Drop here</div> </body></html>
var div = document.createElement('div'); div.setAttribute('class', 'drag'); div.setAttribute('style', 'width:100%'); div.setAttribute('id', 'file' + data.mediaId[i]); div.style.cursor = 'default'; div.appendChild(document.createTextNode(data.mediaName[i])); document.getElementById('jstree').appendChild(div); var mediaIdNew = data.mediaId[i]; $('#file' + mediaIdNew) .on('mousedown', function(e) { return $.vakata.dnd.start(e, {'jstree': true, 'obj': $(this), 'nodes': [{id: true, text: $(this).text(), 'data': {'mediaId': mediaIdNew}}]}, '<div id="jstree-dnd" class="jstree-default"><i class="jstree-icon jstree-er"></i>' + $(this).text() + '</div>'); });'data': {'mediaId': mediaIdNew}
With:
'data': {'mediaId': $(this).attr('id').replace('file','')}
Best regards,
Ivan