JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
First tree
<div id="tree"></div>
Second tree
<div id="tree2"></div>
CSS
#tree {
margin-bottom:80px;
}
JavaScript
var data = [
{ "id" : "root", "parent" : "#", "text" : "Root", "state":{"opened":true} },
{ "id" : "cat1", "parent" : "root", "text" : "First Branch", "state":{"opened":true} },
{ "id" : "cat01", "parent" : "cat1", "text" : "Cat 0.1.0" },
{ "id" : "cat02", "parent" : "cat1", "text" : "Cat 0.1.1" },
{ "id" : "cat03", "parent" : "cat1", "text" : "Cat 0.1.2" }
]
var data2 = [
{ "id" : "cat2", "parent" : "#", "text" : "Second Branch", "state": {"opened":true}},
{ "id" : "cat11", "parent" : "cat2", "text" : "Cat 1.1.0" },
{ "id" : "cat12", "parent" : "cat2", "text" : "Cat 1.1.1" },
{ "id" : "cat13", "parent" : "cat2", "text" : "Cat 1.1.2" }
]
$.jstree.defaults.core = {};
$('#tree').jstree({
'core': {
"multiple": false,
"check_callback": true,
"animation": 200,
"open_parents": true,
"load_open": true,
"state": { "opened": true },
"themes": {
"icons": true,
"responsive": true
},
'data': data
},
"types": {
'max-depth': 1,
"select_node": true,
"open_node": true,
"custom": {
"icon": "url('http://localhost:61939/images/download (2).png')"
}
},
"plugins": ["types", "sort", "dnd", "unique", "ui"]
})
.on('changed.jstree', function (event, data) {
if( data.action == 'select_node'){
$('#tree').find('li').removeClass('disabled_node');
currentlevel = parseInt( $('#'+data.node.id).attr('aria-level') );
$('#tree').find('li').each( function() {
if($(this).attr('aria-level') > currentlevel) {
$(this).addClass('disabled_node');
}
});
}
if( data.action ==...