0
votes

Per the discussion here, currently the ivh-treeview Angular library does not expand collapsed nodes when the tree is filtered and a leaf node matches the filter.

Would the right way to implement this behavior be to add an ng-change handler to the input element used for the filter text and then query the tree in the containing controller (thus, doing it manually)?

There doesn't appear to be any other mechanism by which to detect if the filter is changed.

BTW, there exists no ivh-treeview tag so I can't really tag this properly. Apologies if I've hijacked someone else's tag. That said it appears to be the tag used for other ivh-treeview related questions.

1
@jtrussell, per your request, tagging you here. - icfantv

1 Answers

1
votes

There's really no way to do this elegantly I'm afraid. The best you can do is expand the entire tree (with expandRecursive) when you detect the filter is non-empty (or past some threshold). By completely expanding the tree you get to "show filtered nodes" by virtue of the fact that everything else is hidden by ivhTreeview. That's the easy part. The hard part is when there's no longer a filter how do you restore the tree to it's previous partially-expanded state.

If I had to do it I'd probably end up walking the tree to grab the expanded state from each node before the recursive expand then restore that state when the filter is removed. This would clobber collapse/expand actions while there was a filter in play... you could handle that too but things start to get hairy very quickly. E.g.:

var isExpanded = ivhTreeviewOpts().expandedAttribute

// When the filter becomes non-empty
ivhTreeviewBfs(myTree, function(node) {
  node.savedExpandedState = n[isExpanded]
})
ivhTreeviewMgr.expandRecursive(tree)

// When the filter becomes empty
ivhTreeviewBfs(myTree, function(node) {
  node[isexpanded] = node.savedExpandedState
})

Here's a rough demo: http://jsbin.com/jijoma/3/edit?html,js,output

Hope that helps!