dxrsm
dxrsm

Reputation: 127

How to disable selected node in jstree?

How can I disable default action for the selected node?

When user selects a node, this node should not be clickable, until another node is selected.

This is a very common feature, but I cannot seem to make it work.

Regards

Dimitris

Upvotes: 3

Views: 8641

Answers (1)

dxrsm
dxrsm

Reputation: 127

I solved this by handling the select_node.jstree event and using the types plugin.

var treeConfig = {
    plugins: ["ui", "types"],
    types: {
    valid_children: ["selected"],
        types: {
            "selected": {
                "select_node": false
            }
        }
     }
}

var tree = $("#navtree");

tree.jstree(treeConfig)
    .bind("select_node.jstree", function (e, data){
        tree.find('[rel="selected"]').removeAttr('rel');
        data.rslt.obj.attr("rel", 'selected');
    });

Basically, on select_node, I remove any rel=selected attribute in the tree, and then apply a rel=selected attribute to the selected node. In types, I disable the select_node function for the "selected" type.

Upvotes: 5

Related Questions