Dumi
Dumi

Reputation: 25

Check if all nodes are expanded - jstree

I'm using jstree library and I'm trying to understand how to check if the tree has all it's nodes expanded after I expand one node. This functionality I want to use in order to set a switch on/off weather all nodes are expanded or all nodes are not expanded.

Upvotes: 1

Views: 1541

Answers (2)

Divyanshu Jimmy
Divyanshu Jimmy

Reputation: 2742

There is actually a solution for this using jsTree after_open events (i tried using show_all event but that didn't worked for me ) :

http://jsfiddle.net/softxide/1fnbzjjf/15/

$('#container').on('after_open.jstree', function(e, data) {
        var closed_count = $(".jstree-closed").length;
        if(closed_count == 0)
        {
            alert("all opened");
        }

             }).jstree();

Upvotes: 0

Asif Nowaj
Asif Nowaj

Reputation: 356

If you want to check whether all nodes are at collapsed state or at least one node is expanded then you can use below check.

$('#btnCheck').click(function () {
    $('#status').text("No - all nodes are collapsed");
    if($('#SimpleJSTree li.jstree-open').length)
    {
        $('#status').text("Yes - there is expanded node");
    }
 });

where jsTree id is SimpleJSTree and jstree-open class is being used for expanded node.

For complete example, you can refer https://everyething.com/jsTree-check-for-any-expanded-node

Upvotes: 1

Related Questions