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;
});
The autoCollapse option is messing with expand/collapse. Just comment it out and it works.
$('#tree-team').dynatree({
//autoCollapse: true,
...
});