I'm trying to capture dnd events in jsTree 3.0.0. I used the demo code to build event handlers. The tree builds fine, but the events never fire. What am I missing?
This is the pertinent part. The JSON works fine and builds the tree itself find. However, the console.log calls never occur when I drag and drop on the tree.
<link href="/jquery/jquery-ui-1.10.3/css/ui-lightness/jquery-ui-1.10.3.custom.min.css" rel="Stylesheet"/>
<script src="/jquery/jquery-ui-1.10.3/js/jquery-1.9.1.js"/>
<script src="/jquery/jquery-ui-1.10.3/js/jquery-ui-1.10.3.custom.min.js"/>
<link href="/jquery/plugins/jsTree/themes/default/style.min.css" rel="stylesheet"/>
<script src="/jquery/plugins/jsTree/jstree.js"/>
<script>
$(function () {
$('#jstree')
// listen for events
.on('dnd_start.vakata', function (e, data) {
console.log('Dragged');
})
.on('dnd_stop.vakata', function (e, data) {
console.log('Dropped');
})
// create the instance
.jstree({
"core" : {
"check_callback" : true,
'data' : {
'url' : 'categoriesJson.pm?json=1',
'data' : function(node) {
console.log (node);
return {
'id' : node.id
}
}
},
"themes" : {
"stripes" : true
}
},
"plugins" : [ "dnd" ]
});
$(document).bind("drag_stop.vakata", function (e, data) {
if (data.data.jstree) {
console.log('User stopped dragging');
}
});
});
</script>
The event is only triggered on the "document". Try this:
$(document).on('dnd_start.vakata', function (e, data) {
console.log('Started');
});
It works!
In the documentation https://www.jstree.com/api/#/?q=event&f=dnd_start.vakata
DnD events (dnd_start, dnd_move, dnd_stop) are triggered on document, not on tree.
These events are differents from "move_node.jstree" event, which is called only at the end of Drag & Drop (equivalent to Drop event).
$(document).bind("dnd_start.vakata", function(e, data) {
console.log("Start dnd");
})
.bind("dnd_move.vakata", function(e, data) {
console.log("Move dnd");
})
.bind("dnd_stop.vakata", function(e, data) {
console.log("Stop dnd");
});
$("#tree").jstree({
// tree...
}).bind("move_node.jstree", function(e, data) {
console.log("Drop node " + data.node.id + " to " + data.parent);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With