[CLOSED] Refresh Tree Panel

  1. #1

    [CLOSED] Refresh Tree Panel

    Hello,

    I have a TreePanel created on the fly. The problem is that is not refreshing.
    I tried the method TreePanel.RemoveAll() and to recreate it but it returns an empty control.

    Here is the C# code

    public void PopulateTree()
            {
                Ext.Net.Node root = new Ext.Net.Node()
                {
                    Text = "Categories",                  
                };
                 
                TreePanel1.Root.Add(root);                 
                
                var data = RequestCategoriesController.GetRequestCategories();
     
                foreach (DataLayer.RequestCategory item in data.Where(c => c.ParentFK == null))
                {
                    AddNode(root.Children, item, data);
                }           
            }
     
            private void AddNode(NodeCollection nodes, DataLayer.RequestCategory currentCategory, List<DataLayer.RequestCategory> items)
            {
                Node newNode = new Node()
                {
                    NodeID = currentCategory.SN.ToString(),
                    Text = currentCategory.Name,
                    Expanded = true
                };
                newNode.CustomAttributes.Add(new ConfigItem("SN", currentCategory.SN.ToString()));
                newNode.CustomAttributes.Add(new ConfigItem("Name", currentCategory.Name));
                newNode.CustomAttributes.Add(new ConfigItem("ParentFK", currentCategory.ParentFK.ToString()));
                newNode.CustomAttributes.Add(new ConfigItem("IsActive", currentCategory.IsActive.ToString()));
                nodes.Add(newNode);
                var children = items.Where(x => x.ParentFK == currentCategory.SN);
                 
                if (children.Count() == 0)
                    newNode.Leaf = true;
     
                foreach (var child in children)
                {
                    AddNode(newNode.Children, child, items);
                }           
            }
     
     
     public override void CommandReload(object sender, DirectEventArgs e)
            {
                if (X.IsAjaxRequest)
                {
                    TreePanel1.RemoveAll();
                }
            }
     
     
    protected void TreePanel1_PreRender(object sender, EventArgs e)
            {
     
                if (X.IsAjaxRequest)                            
                    PopulateTree();             
                else
                    PopulateTree(); 
            }
    Code Behind

    <ext:TreePanel ID="TreePanel1" OnPreRender="TreePanel1_PreRender"
                        runat="server"           
                        ForceFit="true"
                        Region="Center"                                               
                        UseArrows="true"
                        RootVisible="false"
                        MultiSelect="true"
                        SingleExpand="true"                   
                        FolderSort="true">                                     
                        <Listeners>
                            <ItemClick Fn="getSN"/>                       
                        </Listeners>                   
                        <Store>                        
                            <ext:TreeStore ID="TreeStore1" runat="server" OnLoad="TreeStore1_Load" >
                                <Proxy>
                                    <ext:PageProxy />
                                </Proxy>                           
                                 
                                <Model>
                                    <ext:Model runat="server">
                                        <Fields>                        
                                        <ext:ModelField Name="SN"/>
                                        <ext:ModelField Name="Name" />
                                        <ext:ModelField Name="ParentFK" /> 
                                        <ext:ModelField Name="IsActive" />                        
                                    </Fields>
                                    </ext:Model>
                                </Model>                           
                            </ext:TreeStore>
                        </Store>
     
                        <ColumnModel>
                            <Columns>                                                      
                                <ext:TreeColumn OnPreRender="Unnamed_PreRender"
                                    runat="server"
                                    Text="<%$Resources:DBFields , RequestCategories_Name %>"                                                                                            
                                    Sortable="true"
                                    DataIndex="Name">  
                                    <Renderer*Fn="Link"/>
                                    </ext:TreeColumn>                           
                                <ext:CheckColumn ID="Column3"
                                    runat="server"
                                    Text="<%$Resources:DBFields , RequestCategories_IsActive %>"
                                    Sortable="true"                                
                                    DataIndex="IsActive" />
                            </Columns>
                        </ColumnModel>
                    </ext:TreePanel>
    Any idea on how I could refresh the TreePanel?

    Thanks
    Last edited by Daniil; Sep 25, 2013 at 5:24 AM. Reason: [CLOSED]
  2. #2
    Hi @S.KARATHANASIS,

    If you use a PageProxy, it is supposed that you should load the nodes via a TreeStore's OnReadData handler.
    https://examples2.ext.net/#/TreePanel/Loaders/Page/

    As far as I can see you are populating a TreePanel's Root. So, you probably do not need a PageProxy. Maybe, you need something like this:
    https://examples2.ext.net/#/TreePane...h_Static_Tree/
  3. #3
    Hello Daniil,

    Thanks for the reply. It was very helpful.

Similar Threads

  1. [CLOSED] Refresh tree using DirectEvent
    By bayoglu in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Mar 05, 2013, 1:04 PM
  2. Replies: 11
    Last Post: Oct 07, 2011, 9:14 AM
  3. Replies: 8
    Last Post: May 28, 2009, 8:18 PM
  4. How to refresh tree using CodeBehind and VB?
    By dbassett74 in forum 1.x Help
    Replies: 0
    Last Post: Apr 21, 2009, 2:47 PM
  5. Replies: 3
    Last Post: Jan 03, 2009, 10:41 PM

Posting Permissions