angular-tree-control icon indicating copy to clipboard operation
angular-tree-control copied to clipboard

Collapse children of collapsed node possible?

Open mike-ward opened this issue 8 years ago • 3 comments

Open a node several levels deep. Then collapse the first node opened. The nodes expanded under the first node are still expanded. You can see this by reopening a node. Is there a way to collapse the children of the collapsed node? If not maybe add a configuration option?

mike-ward avatar Jun 16 '17 18:06 mike-ward

the list of expanded nodes is managed in the expanded nodes array. Just remove from it what you do not wanna have there.

I did not implement the logic to do so automatically.

Having such a configuration option sounds nice, if you create a PR (with tests) will merge it.

yoavaa avatar Jun 20 '17 22:06 yoavaa

I looked at the array before posting this issue. I didn't see a way to determine if a node was a child of another (no parent reference). Maybe there's something I don't understand about the structure.

mike-ward avatar Jun 21 '17 12:06 mike-ward

For what it's worth I was able to write a function to do this. Hooked it into the on-toggle-node event.

function collapseNode(node): void {
    scope.expandedNodes = scope.expandedNodes.filter(en => isNotChild(node, en));
}

function isNotChild(node, en): boolean {
    if (!node.children) return true;
    return node.children.every(n => n !== en && isNotChild(n, en));
}

mike-ward avatar Jun 21 '17 17:06 mike-ward