Problem with expanding nodes

7 posts, 0 answers
  1. Massimo
    Massimo avatar
    4 posts
    Member since:
    Sep 2008

    Posted 31 Oct 2008 Link to this post

    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?
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 03 Nov 2008 Link to this post

    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.
  3. Massimo
    Massimo avatar
    4 posts
    Member since:
    Sep 2008

    Posted 04 Nov 2008 Link to this post

    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.
  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 06 Nov 2008 Link to this post


    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.
  5. Massimo
    Massimo avatar
    4 posts
    Member since:
    Sep 2008

    Posted 06 Nov 2008 Link to this post

    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).
  6. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 07 Nov 2008 Link to this post

    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.
  7. Markus
    Markus avatar
    103 posts
    Member since:
    Dec 2007

    Posted 23 Dec 2008 Link to this post

    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 :(
Back to Top