Using jstree is it possible to block the collapse of a single specific node?
I have a tree structure which can be expanded/collapsed at will... but I have certain nodes that should always be open and not allow the user to collapse them.
Is there a way to block the collapse (maybe through the data-jstree attribute on the <li>)... and if possible, a way to also remove the triangle against the item?
I've tried hooking into the close_node.jstree event but neither using a return false or e.preventDefault() is stopping it happening.
In the following example, I want the "Item 2 - Must Keep Open" to ALWAYS be open, and not allow the user to hide the "Always Visible" item...
$(function() {
$("#treeRoot").jstree({
core: {
themes: {
variant: "small"
}
}
});
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
<div id="treeRoot">
<ul>
<li data-jstree='{"opened":true}'>Root
<ul>
<li>Item 1</li>
<li data-jstree='{"opened":true}'>Item 2 - Must keep open
<ul>
<li>Always Visible</li>
</ul>
</li>
<li>Item 3</li>
</ul>
</li>
</ul>
</div>