Question

I use Dynatree to get a tree view and now I want to expand/collapse all nodes, but only the last node of my tree expands.

You can see this effect in the fiddle: http://jsfiddle.net/aA76N/2/

The following is my code which I use to expand/collapse the nodes.

$('.panel-heading').on('click', '.expand-all', function() {
    $('#tree-team').dynatree('getRoot').visit(function(node) {
        node.expand(true);
    });
    $(this).children().removeClass('glyphicon-folder-open').addClass('glyphicon-folder-close');
    $(this).removeClass('expand-all').addClass('collapse-all');
    return false;
});

$('.panel-heading').on('click', '.collapse-all', function() {
    $('#tree-team').dynatree('getRoot').visit(function(node) {
        node.expand(false);
    });
    $(this).children().removeClass('glyphicon-folder-close').addClass('glyphicon-folder-open');
    $(this).removeClass('collapse-all').addClass('expand-all');
    return false;
});
Was it helpful?

Solution

The autoCollapse option is messing with expand/collapse. Just comment it out and it works.

http://jsfiddle.net/aA76N/4/

$('#tree-team').dynatree({
    //autoCollapse: true,
    ...
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top