I have a fancy tree solution on my website and i would like to have a button that will trigger a specific node.
Can i activate a specific node from a button click or trigger it after the fancy tree has loaded?
My fancytree code:
$("#tree").fancytree({ //Fancy Tree
checkbox: false,
selectMode: 3,
extensions: ["dnd"],
source: {
url: "@(Url.Action("GetCategoryForFancyTree", "LinksDocuments"))" + '?time=' + timestamp,
success: function(data){
console.log(data);
},
cache: true
}
});
I saw that this code maybe i could use but i dont dont know the node key for the node, how could i retrieve the key?
$("#tree").fancytree("getTree").getNodeByKey("id4.3.2").setActive();
The .getNodeByKey is just expecting the "id" of the node element. For example to get the "Sample Node" from the following example just set the id for each element:
<div id="tree">
<ul>
<li id="123">Sample Node</li>
</ul>
</div>
And use something like this to activate it:
$("#tree").fancytree("getTree").getNodeByKey("123").setActive();
I recommend adding this to the "init: function() {}" otherwise it may not activate if the tree is still loading/building.
Can also use the following from within the "init:", should do the same.
data.tree.activateKey("123")
Finally, to get the key if you don't already know it:
click: function (event, data) {
var node = data.node;
alert("ID: " + node.key);
}
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