[CLOSED] Reloading TreePanel Nodes dynamically in a Direct Event

  1. #1

    [CLOSED] Reloading TreePanel Nodes dynamically in a Direct Event

    I have a TreePanel with a Node and I need to load the tree based on user input from a combo box. The items/text etc. in the nodes are derived from a database query (linq objects). There are also things that are removed based on who is logged in etc. so my load/reload needs to be in code behind direct event in order to access the data model. When the form loads, the tree/nodes are loaded and looks great. When my direct even is called, the nodes in the form are not refreshed. My searches for this in this forum returns all 1.x related problems.

    Thanks in advance,
    Robb

        <ext2:TreePanel ID="menuActions" runat="server" RootVisible="false" Border="false">
                                        <Root>
                                            <ext2:Node NodeID="root" Text="Actions" Expanded="true" />
                                        </Root>
        </ext2:TreePanel>
           <DirectMethod()>
            Public Sub ContextSelect(sender As Object, e As DirectEventArgs)
    
                Dim root As Ext.Net.Node = menuActions.Root.Primary
                Dim groups As New SortedDictionary(Of String, Ext.Net.Node)
                Dim groupleaves As New SortedDictionary(Of String, SortedDictionary(Of String, Ext.Net.Node))
                Dim leaves As New SortedDictionary(Of String, Ext.Net.Node)
    
    ' actions is an ienumerable with data rows specific to user input
    
              For Each a In actions.OrderBy(Function(o) o.Group_vc).ThenBy(Function(o) o.Name_vc)
    
                        If Not groups.ContainsKey(a.Group_vc) Then
                            Dim treeNode As New Node
                            With treeNode
                                .Text = a.Group_vc
                                .Icon = Icon.Folder
                                .Expanded = True
                            End With
                            groups.Add(a.Group_vc, treeNode)
                            leaves = New SortedDictionary(Of String, Ext.Net.Node)
                        End If
    
                        If Not groupleaves.ContainsKey(a.Group_vc) Then
                            leaves.Add(a.Key_vc, New Ext.Net.Node With {
                                    .NodeID = a.Key_vc,
                                    .IconFile = ActionNewBasePage.GetImage(a),
                                    .Leaf = True,
                                    .Text = a.Name_vc
                                })
    
                            groupleaves.Add(a.Group_vc, leaves)
                        Else
                            groupleaves(a.Group_vc).Add(a.Key_vc, New Ext.Net.Node With {
                                    .NodeID = a.Key_vc,
                                    .IconFile = ActionNewBasePage.GetImage(a),
                                    .Leaf = True,
                                    .Text = a.Name_vc
                                })
                        End If
                        'then add the node to the group
    
                Next
                ''add the group nodes to the root
                For Each kvp In groups
                    For Each nkvp In groupleaves(kvp.Key)
                        kvp.Value.Children.Add(nkvp.Value)
                    Next
                    root.Children.Add(kvp.Value)
                Next
    End Sub
    Last edited by Daniil; Mar 17, 2014 at 11:54 AM. Reason: [CLOSED]
  2. #2
    Hi @Robb,

    If you change a TreePanel's Root during a DirectEvetn, it won't affect to client automatically. You can call a TreePanel's Render method
    menuActions.Render()
    Then an entire TreePanel will be re-rendered with new nodes.

    Another possible approach is:
    https://examples2.ext.net/#/TreePane...h_Static_Tree/
  3. #3
    Thanks, I was trying DoLayout but Render is what I was missing.

Similar Threads

  1. Replies: 5
    Last Post: Dec 21, 2015, 8:39 PM
  2. TreePanel Add new nodes direct method
    By rajatmig29 in forum 2.x Help
    Replies: 2
    Last Post: Oct 10, 2013, 8:45 AM
  3. Dynamically Added Button Direct Event Does Not Work
    By rosencrantz in forum 1.x Help
    Replies: 1
    Last Post: Apr 19, 2011, 9:41 AM
  4. Replies: 12
    Last Post: Jan 01, 2011, 1:36 AM
  5. TreePanel Add/Delete nodes dynamically
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 18, 2008, 7:32 PM

Posting Permissions