jsTree dnd events not firing

GeoJunkie picture GeoJunkie · Apr 29, 2014 · Viewed 16.8k times · Source

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>                   

Answer

Sandro Stadler picture Sandro Stadler · Aug 8, 2014

The event is only triggered on the "document". Try this:

$(document).on('dnd_start.vakata', function (e, data) {
    console.log('Started');
});

It works!