This is a migrated thread and some comments may be shown as answers.

RadTreeNode - Client Side Expanding Specific Nodes

1 Answer 187 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
EmpowerIT
Top achievements
Rank 2
EmpowerIT asked on 06 Nov 2013, 07:03 AM
Hi there,

I'm using the RadTreeView with the ExpandMode of SeverSideCallBack.

Here's the situation:

TreeView opens a RadWindow which than closes and fires off my RadWindowClose event.

In that event, i look for parent nodes that have expanded child nodes of specific type (i.e:. File). I then clear the child nodes, toggle and expand the node again.

Example:

Root Node
-Folder
-SubFolder
-File
-File

Problem is. I clear SubFolder Node and execute expand()
I then do the same on Folder because it has a File Node

I get into the situation where SubFolder hasn't expanded yet and i'm telling Folder to expand causing all sorts of weird jscript errors

Any ideas.




1 Answer, 1 is accepted

Sort by
0
EmpowerIT
Top achievements
Rank 2
answered on 07 Nov 2013, 12:28 AM
For those interested in how I solved my problem,

First i sort my nodes by get_level, this allows it to always put the parent on top of the array list:

function compare(a, b) {
    if (a.get_level() < b.get_level())
        return -1;
    if (a.get_level() > b.get_level())
        return 1;
    return 0;
}
 
 parentNodes.sort(compare);

 i loop through my list of sorted array nodes, expand the first node (top level node), add it to a temp array list, remove the newly expanded node from the list. once expanded my OnClientNodePopulatedHandler checks the temp array list for any node, it finds the next node in the list by value than expands that node, removes it from the temp array list and so on.


var toExpandNodes = [];
 
function ProcessNodes(arrayList) {
    for (var i = 0; i < arrayList.length; i++) {
        var node = arrayList[i];
        var isNodeExpanded = node.get_expanded();
        var nodeValue = node.get_value();
        var tree = $find("ctl00_PlaceHolderMain_RadTreeView22");
        tree.trackChanges();
        if (tree.findNodeByValue(nodeValue) != null) {
            node = tree.findNodeByValue(nodeValue);
            node.get_nodes().clear();
            node.set_expandMode('2');
            tree.commitChanges();
            if (isNodeExpanded == true) {
                node.toggle();
                node.expand();
                RemoveOldNodes(arrayList, node.get_value());
                break;
            }
        }
    }
}
 
function RemoveOldNodes(arrayList, value) {
    var i = arrayList.length;
    while (i--) {
        if (arrayList[i].get_value() == value) {
            arrayList.splice(i, 1);
        }
    }
    toExpandNodes = arrayList;
}
 
function processNode() {
    var i = window.toExpandNodes.length;
    while (i--) {
        var node = window.toExpandNodes[i];
        var isNodeExpanded = node.get_expanded();
        var nodeValue = node.get_value();
        var tree = $find("ctl00_PlaceHolderMain_RadTreeView22");
        tree.trackChanges();
        if (tree.findNodeByValue(nodeValue) != null) {
            node = tree.findNodeByValue(nodeValue);
            node.get_nodes().clear();
            node.set_expandMode('2');
            tree.commitChanges();
            if (isNodeExpanded == true) {
                node.toggle();
                node.expand();
                RemoveOldNodes(window.toExpandNodes, node.get_value());
                break;
            }
        }
    }
}

On my treeview i have enabled the onclientnodepopulated client event

function OnClientNodePopulatedHandler(sender, e) {
    if (window.toExpandNodes.length > 0) {
            processNode();
    }
}

Forgive my stupid variable/array/function names, I did this late at night.
Tags
TreeView
Asked by
EmpowerIT
Top achievements
Rank 2
Answers by
EmpowerIT
Top achievements
Rank 2
Share this question
or