Can someone post an example of a move_node event handler?

2,956 views
Skip to first unread message

PAinVA

unread,
Feb 28, 2014, 5:48:41 PM2/28/14
to jst...@googlegroups.com
 I tried binding move_node to the document and to the tree.  It doesn't fire.  Am I missing something?  Will move_node trigger on a foreign drag (from a div)?

Peter      

        $("#object-tree").jstree({
            'core'      : {"check_callback": true, 'data' : function (obj, cb) {cb.call(this,objects_tree_data)}},
            'plugins'   : ['dnd']
        })

        $(document).on('move_node.jstree', function (e, data) {
                alert("Heard a move");
        })

Ivan Bozhanov

unread,
Feb 28, 2014, 6:30:54 PM2/28/14
to jst...@googlegroups.com
For foreign drags and drops read this: https://groups.google.com/d/msg/jstree/BYppISuCFRE/KKh7oHZzNkwJ
As for the event - it will fire on the DIV - so listen for:
$("#object-tree").on('move_node.jstree', ...

You could also listen for copy_node too.

Best regards,
Ivan

PAinVA

unread,
Feb 28, 2014, 9:57:53 PM2/28/14
to jst...@googlegroups.com
You nailed it Ivan, I got it working thanks.  I read the comment on foreign divs and I got that working too.  I'm curious of your opinion on something.

For my drag and drops I'd actually like the server to do the move and the client (browser) just reloads the updated JSON (which reflects the move) to form the proper tree.  Make sense?

In that case I see two paths

1.  Unbind the default dnd_stop.vakata handler and create my own dnd_stop.vakata handler which tells the server that a node has been moved/copied, server does the move and then I refresh the tree with the new JSON (via AJAX).

OR

2.  Leave the dnd_stop.vakata event handler and just trigger the AJAX refresh call using the move/copy event handlers.

I tried #1 and it works (in the sense that I can issue an AJAX refresh) but I'm not sure how to figure out parent node, node, etc from the data argument of dnd_stop.vakata

#2 seems easier; jstree will complete the drop like normal and then my refresh will along a moment later.

Thoughts?

Peter

Ivan Bozhanov

unread,
Mar 1, 2014, 3:22:54 AM3/1/14
to jst...@googlegroups.com
2 should be fine ... just bind to move_node:
on('move_node.jstree', function (e, data)) { data.instance.refresh(); }

Best regards,
Ivan
Reply all
Reply to author
Forward
0 new messages