Edit As pointed out by @charles, disabling nodes does not disable the menu plugin (at least using a custom menu) or drag'n'drop - point 4 has been added to take care of this
To disable the whole tree
- Disable all displayed nodes - disable each node by id or get an array of identifiers for one call to disable_node
- Prevent opening new nodes - intercept and block the click event on the open icon
- Prevent the opening of new nodes by double-clicking - change the current tree settings
- If the tree is modified by the user in any way, temporarily disable all settings
core.check_callback = false
Note Point 2 is based on undocumented features and (given the history of the jstree plugin) probably won't work in future releases
See snippet for demonstration.
var data1 = [{ "id": "W", "text": "World", "state": { "opened": true }, "children": [{"text": "Asia"}, {"text": "Africa"}, {"text": "Europe", "state": { "opened": false }, "children": [ "France","Germany","UK" ] }] }]; $('#Tree').jstree({ core: {data: data1, check_callback: true }, plugins: ['dnd','contextmenu','checkbox'] }) function DisableFlawed() {
<link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" type="text/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> <button onclick="DisableFlawed()">Disable (bad)</button> <button onclick="Disable()">Disable (ok)</button> <button onclick="Enable()">Enable</button> <div id="Tree"></div>
source share