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

Problem with expanding nodes

6 Answers 164 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Massimo
Top achievements
Rank 1
Massimo asked on 31 Oct 2008, 12:02 PM
I have set up a context menu on a treeview that has an "Expand All" option. This option will basically create all the underlying children node and expand them. The function basically relieves the user f having to click all the way down the tree.

The problem is that when I click on any of the underlying nodes, the OnNodeExpand event kicks off (which has code to expand the node). Is there anyway, I can set all these nodes to just open and close without setting off OnNodeExpand?

6 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 03 Nov 2008, 11:03 AM
Hello Massimo,

Can you send us the code of your implementation? I am not sure what exactly the probelm is.


Regards,
Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Massimo
Top achievements
Rank 1
answered on 04 Nov 2008, 04:10 PM
If I right-click on a node, a contect menu comes up. Once of the options is to Expand all children nodes:

protected void ExpandAll(RadTreeNode node)  
        {  
            node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;  
             
            switch (node.Attributes["NodeType"])  
            {  
                case "ReportSummary":  
                    PopulateParentHoliding(node);  
                    break;  
 
                case "ParentHolding":  
                    PopulateParentHoliding(node);  
                    break;  
 
                case "OwnHolding":  
                    PopulateInstrumentHolding(node);  
                    break;  
 
                case "InstrumentHolding":  
                    PopulateBookHolding(node);  
                    break;  
 
                case "BookHolding":  
                    PopulateNativeData(node);  
                    break;  
            }  
            node.ExpandChildNodes();  
            node.Expanded = true;  
 
            //Still need to work out how to set the nodes to expanded. Post raised in forum.  
 
            foreach (RadTreeNode childNode in node.Nodes)  
            {  
                ExpandAll(childNode);  
            }  
        } 

Basically, this fires off a bit of node generation code, depending on what time of information the node pertains to. An example of such  a function for a node is:

protected static void PopulateInstrumentHolding(RadTreeNode node)  
        {  
            NodeData nodeData = new NodeData();  
            List<InstrumentHolding>  instrumentHoldingList = nodeData.InstrumentHolding(node);  
            NodeGeneration nodeGeneration = new NodeGeneration();  
 
            instrumentHoldingList.ForEach(delegate(InstrumentHolding instrumentHolding)  
            {  
                node.Nodes.Add(nodeGeneration.GenerateInstrumentHoldingNode(instrumentHolding));  
            });  
        } 

Basically, lots of child nodes can be added without me ever clicking on the node expansion (and as the function is recursive, there can be a fair number of levels.

After this, all the nodes should have an - image instead of a + one. However, the nodes behave as if they have never been expanded.
0
Peter
Telerik team
answered on 06 Nov 2008, 10:22 AM

Alright, I understand. In this case, I suggest the following client-side solution:

<asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
    <script type="text/javascript">  
        function expandChildNodes(node)   
        {  
            node.expand();             
          var nodenodes = node.get_nodes();           
            for (var i = 0; i < nodes.get_count(); i++) {  
                if (nodes.getNode(i).get_nodes() != null) {  
                    expandChildNodes(nodes.getNode(i));  
                }                  
            }  
        }  
        function OnClientContextMenuItemClicking(sender, eventArgs)   
        {  
            expandChildNodes(eventArgs.get_node());  
        }      
    </script> 
    <telerik:RadTreeView ID="RadTreeView1" runat="server" OnClientContextMenuItemClicking="OnClientContextMenuItemClicking">  
        <Nodes> 
            <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1">  
                <Nodes> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">  
                    </telerik:RadTreeNode> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">  
                        <Nodes> 
                            <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">  
                            </telerik:RadTreeNode> 
                            <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">  
                                <Nodes> 
                                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">  
                                        <Nodes> 
                                            <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">  
                                            </telerik:RadTreeNode> 
                                            <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">  
                                            </telerik:RadTreeNode> 
                                        </Nodes> 
                                    </telerik:RadTreeNode> 
                                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">  
                                    </telerik:RadTreeNode> 
                                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 3">  
                                    </telerik:RadTreeNode> 
                                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 4">  
                                    </telerik:RadTreeNode> 
                                </Nodes> 
                            </telerik:RadTreeNode> 
                            <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 3">  
                            </telerik:RadTreeNode> 
                        </Nodes> 
                    </telerik:RadTreeNode> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 3">  
                    </telerik:RadTreeNode> 
                    <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 4">  
                    </telerik:RadTreeNode> 
                </Nodes> 
            </telerik:RadTreeNode> 
            <telerik:RadTreeNode runat="server" Text="Root RadTreeNode2">  
            </telerik:RadTreeNode> 
            <telerik:RadTreeNode runat="server" Text="Root RadTreeNode3">  
            </telerik:RadTreeNode> 
        </Nodes> 
        <CollapseAnimation Type="OutQuint" Duration="100"></CollapseAnimation> 
        <ExpandAnimation Duration="100"></ExpandAnimation> 
        <ContextMenus> 
            <telerik:RadTreeViewContextMenu ID="ContextMenu1" runat="server" > 
            <Items> 
            <telerik:RadMenuItem Text="Expand all child nodes"</telerik:RadMenuItem> 
            </Items> 
            </telerik:RadTreeViewContextMenu> 
        </ContextMenus> 
    </telerik:RadTreeView> 



Greetings,
Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Massimo
Top achievements
Rank 1
answered on 06 Nov 2008, 01:17 PM
Thank you very much for the answer. I gave it a try but got a couple of problems after incorporating it into my application:

1) It only expanded the first layer of child nodes. With the data I am using, it should go 5 layers deep.

2) When I clicked on expand all on one of the child nodes, I got the following error:

Error: 'this._loadingStatusElement.parentNode' is null or is not an object.

After looking at your example, there is one thing I might not have pointed out very clearly. Initially, the tree only has the parent nodes. There is nothing underneath. Child nodes are added wither by doing an Expand (which kicks of some C# to add the node) or by doing ExpandAll (which in your nice exmaple forces a node expand).
0
Peter
Telerik team
answered on 07 Nov 2008, 09:36 AM
Hi Massimo,

With load-on-demand implementation it is not possible to achieve the desired functionality. RadTreeeView doesn't expose a server-side Expand() method which would allow this functionality.


Greetings,
Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Markus
Top achievements
Rank 2
answered on 23 Dec 2008, 08:31 AM
You can achieve the desired functionality with something like this: (it works in my case)

var oldNodes; // b/c you can't provide parameters with setTimeOut
function expandAll()
{
// check if old nodes are expanded:
var expanded=true;
if(oldNodes != null)
{
for(var i = 0; i < oldNodes.length; i++)
{
if(!oldNodes[i].get_expanded())
{
expanded=false;
break;
}
}
}
if(expanded) {
var nodes = tree.get_allNodes();
if(nodes != null)
{
for(var i = 0; i < nodes.length; i++)
{
nodes[i].expand();
}
oldNodes = nodes;
}
}
if(nodes != null) {
window.setTimeOut("expandAll()",10);
}
}

edit: a better way to see if a node has finished loading is:
if(node._loadingStatusElement != null && node._loadingStatusElement.readyState = "complete")

is this true @ telerik team ???

found no documentation on this topic :(
Tags
TreeView
Asked by
Massimo
Top achievements
Rank 1
Answers by
Peter
Telerik team
Massimo
Top achievements
Rank 1
Markus
Top achievements
Rank 2
Share this question
or