Expand all nodes inside the RadTreeView of a RadFileExplorer on page load

1 Answer 59 Views
FileExplorer
Evan
Top achievements
Rank 1
Evan asked on 27 Sep 2023, 06:57 AM

Hi. I have a RadFileExplorer and I would like to expand all of the nodes in its RadTreeView in the left hand panel on page load.

I have tried numerous ways in the code behind as well as JavaScript. The best I could manage was to expand the first node, but nothing more.

I appreciate any suggestions.

Thanks.

Rumen
Telerik team
commented on 28 Sep 2023, 11:41 AM

Hi Evan,

The following JS solution, based on this article, expands all tree nodes on my side:

        <telerik:RadFileExplorer ID="RadFileExplorer1" runat="server" OnClientLoad="OnClientLoad">
            <Configuration ViewPaths="~/Images" UploadPaths="~/Images" />
        </telerik:RadFileExplorer>
        <script>
            function OnClientLoad(sender, args) {
                treeExpandAllNodes(sender)
            }
            function treeExpandAllNodes(sender) {
                var treeView = sender.get_tree()
                var nodes = treeView.get_allNodes();
                for (var i = 0; i < nodes.length; i++) {

                    if (nodes[i].get_nodes() != null) {
                        nodes[i].expand();
                    }
                }
            }
        </script>

Evan
Top achievements
Rank 1
commented on 03 Oct 2023, 01:15 AM | edited

Hi Rumen,

Thanks, this is what I have already tried unsuccessfully.

What I have found is that nodes will only expand up to 3 directories deep in your file system.

e.g. if you had this folder structure...

~/Images/Folder1/Folder2/Folder3/Folder4/Folder5

The Images, Folder1 and Folder2 nodes / directories will be expanded on load, but you will have to manually expand the rest of the child directories i.e expand Folder2 to see Folder3, and so on.

In my application, I need to expand all child directories.

Evan
Top achievements
Rank 1
commented on 09 Oct 2023, 11:08 PM

Thank you very much Rumen, this is the answer I've been searching for!

I can confirm this now works inside my RadFileExplorer to expand all sub nodes perfectly.

I really appreciate your help :)

Rumen
Telerik team
commented on 10 Oct 2023, 05:33 AM

Thank you! I am glad that the solution helped to achieve your scenario :)

1 Answer, 1 is accepted

Sort by
1
Accepted
Rumen
Telerik team
answered on 05 Oct 2023, 11:05 AM

Thank you for the clarification and for sharing this scenario!

RadFileExplorer is using callbacks to populate the expanded nodes. In order to expand all nodes of the tree you need to handle the Tree's ClientNodePopulated client-side event and to manually expand the sub-nodes of the currently expanded node.

Here is an example:

<telerik:RadFileExplorer ID="RadFileExplorer1" runat="server" OnClientLoad="OnClientLoad">
    <Configuration ViewPaths="~/Images" UploadPaths="~/Images" />
</telerik:RadFileExplorer>
<script type="text/javascript">
    function OnClientLoad(explorer, args) {
        var tree = explorer.get_tree();//get reference to the TreeView
        tree.add_nodePopulated(nodePopulated);//attach ClientNodePopulated handler
        expandSubNodes(tree);//manually expand initially visible nodes
    }
    function nodePopulated(sender, args) {
        var currentNode = args.get_node();//get reference to the expanded node
        expandSubNodes(currentNode);
    }
    function expandSubNodes(parent) {
        var nodes = parent.get_allNodes();//get an array of all sub-nodes
        for (var i = 0; i < nodes.length; i++) {
            nodes[i].expand();
        }
    }
</script>

Tags
FileExplorer
Asked by
Evan
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or