Search code examples
jqtree

Preventing the jqTree UI from displaying the option to drop into node for some nodes


I have the following:

    $('#sidebar-tree').tree({
        data: data,
        autoOpen: false,
        dragAndDrop: true,
        selectable: false,
        closedIcon: $('<i class="fas fa-angle-up"></i>'),
        openedIcon: $('<i class="fas fa-angle-down"></i>')
    })

Though for some nodes, I'd like to allow the user to reorder them (so dragging the node between nodes is cool) but I want to prevent the user from dropping them into other nodes. Is there a way to configure this "permitted behavior" per node?

Note: this has been asked on GitHub here: https://github.com/mbraak/jqTree/issues/598


Solution

  • You can use the onCanMoveTo option: https://mbraak.github.io/jqTree/#options-oncanmoveto

    I think the onCanMoveTo should look like this (not tested it):

    onCanMoveTo: function(moved_node, target_node, position) {
      return position !== 'inside';
    }