i'm doing a project where i can search a node withing my treeView my code so far is this:
I need a simple code so when i search the tree for the second time all
the opened nodes should be collapsed and only the searched one is
expended
function expandAllAncestors(node) {
if (node.get_expanded() !== true)
node.expand();
if (node.get_level() != 0) {
expandAllAncestors(node.get_parent());
}
}
function SearchClick() {
var search = $get("<%= ApplicationSearchResult.ClientID %>").value;
var treeView = $find("<%= MainTree.ClientID %>");
var nodes = treeView.get_allNodes();
var NextNode = document.getElementById("<%=NextNode.ClientID %>");
NextNode.style.display = "block";
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
if (node.get_text() == search) {
node.set_selected(true);
expandAllAncestors(node);
return;
}
}
}