LokmanLuke
LokmanLuke

Reputation: 71

Collapse tree after checking all nodes with jsTree

I am using jsTree to display a tree. I want to select all the nodes in the tree of which I can use $("#my-tree").jstree("check_all"). This works fine.
However, this will expand all the nodes and having a big tree will push the rest of the content all the way down.
I want to collapse the tree after checking all the nodes but using $("#my-tree").jstree("close_all") after checking all nodes doesn't work.

Anyone has a solution to this?

$("#my-tree").jstree({
"checkbox": {
    "keep_selected_style": false
},
"plugins": ["checkbox"]});

$("#my-tree").jstree("hide_dots");
$("#my-tree").jstree("check_all");
$("#my-tree").jstree("close_all");

Upvotes: 2

Views: 1339

Answers (1)

Chino Lin
Chino Lin

Reputation: 21

You can use ready.jstree event Should use something like this:

var jstreeid = $('#jstree_counties');
jstreeid.jstree({'plugins':["wholerow","checkbox"], 'core' : {
    'data' : {
        "url" : "json url",
        "dataType" : "json"
    }
}
}).on('ready.jstree', function () {
    jstreeid.jstree("close_all");
});

Upvotes: 1

Related Questions