[CLOSED] TreePanel + Root

  1. #1

    [CLOSED] TreePanel + Root

    Hello

    I have the problem with root item of the treepanel ( treegrid)
    So far I found this:
    - Root must be present ( otherwise js error is thrown on rendering)
    - The attributes of root item is impossible to change

    here is my simple example what I want to achieve - in short - I want to have root item text to be dynamic according the text on previous tab.
    As well I don't want to load the tree on IsPostBack==false, but when the tab is activated.
    The problem is that text of root item does not changes - I moreless undertand that, simply after rendering it seems to be immutable, which is ok.
    But how to deal with that? I tried to hide the root item (the idea was that my "dynamic" root item will be the first child item but the problem was that the ReadData event was then fired immediatelly when the page was rendered - and never again. Maybe some magic with 'beforeload' event and reload method will work here?

    The example code:

     <script>
             function tabChanged(panel,newTab) {
                 
                 if(newTab.id=='<%=treeAssignedParts.ClientID %>')
                     <%=treeAssignedParts.ClientID %>.getRootNode.expand();
             }
         </script>
         <form runat="server">
            <ext:ResourceManager runat="server"  Theme="Gray" Namespace="" />
            <ext:TabPanel runat="server" ActiveTabIndex="0">
                <Listeners>
                    <TabChange Fn="tabChanged"></TabChange>
                </Listeners>
                <Items>
                    <ext:Panel Title="Tab1">
                        <Items>
                            <ext:TextField runat="server" ID="txt" Text="from textbox"/>
                        </Items>
                    </ext:Panel>
                    <ext:TreePanel ID="treeAssignedParts" runat="server" Height="150" RootVisible="true" Title="Tab with tree" >
                            <Fields>
                                <ext:ModelField Name="itemId" />
                                
                            </Fields>
                            <Store>
                                <ext:TreeStore ID="TreeStore1" runat="server" OnReadData="store_readData" >
                                    <Proxy>
                                        <ext:PageProxy />
                                    </Proxy>
                                </ext:TreeStore>
                            </Store>
                            <Root>
                                <ext:Node >
                                    <CustomAttributes>
                                        <ext:ConfigItem Name="itemId" Value="xxx" Mode="Value"/>
                                    </CustomAttributes>
                                </ext:Node>
                            </Root>
                            <ColumnModel>
                                <Columns>
                                    <ext:TreeColumn ID="TreeColumn1" Header="ItemId" Width="90" DataIndex="itemId" SortType="AsInt" runat="server">
                                    </ext:TreeColumn>
                                </Columns>
                            </ColumnModel>
                        
                            
                        </ext:TreePanel>
                </Items>
            </ext:TabPanel>

    protected void store_readData(object sender, NodeLoadEventArgs e)
        {
            treeAssignedParts.Root[0].Text = txt.Text;
            e.Nodes.Add(new Node()
                            {
                                CustomAttributes = {
                                    new ConfigItem("itemId","First CHild",ParameterMode.Value)
                            }
                            });
        }
    Last edited by Daniil; Oct 12, 2012 at 6:07 AM. Reason: [CLOSED]
  2. #2
    Hi @aisi_it_admin,

    Root must be present ( otherwise js error is thrown on rendering)
    Seems it was fixed some time ago. At least, I was unable to reproduce.

    The attributes of root item is impossible to change
    Yes, setting Text and populating CustomAttributes doesn't make any sense if the Node is already rendered as it is in your case.

    You can change it client side directly within the TabChange listener.

    Example
    App.TreePanel1.getRootNode().set("text", "new text");
    If you do need to change it on server side, it is also possible.

    Example
    this.TreePanel1.GetRootNode().SetText("new text");
    I tried to hide the root item (the idea was that my "dynamic" root item will be the first child item but the problem was that the ReadData event was then fired immediatelly when the page was rendered - and never again.
    Because the root node is already expanded when you call its expand methods.

    You can set this setting to avoid auto-loading on initial page load.
    AutoLoad="false"
    The TreeStore's load and reload methods can help as well.

Similar Threads

  1. TreePanel without Root node
    By Dominik in forum 1.x Help
    Replies: 3
    Last Post: Jun 25, 2014, 7:07 PM
  2. [CLOSED] Treepanel root visible
    By softmachine2011 in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 12, 2012, 10:38 AM
  3. TreePanel - load root with loader
    By pintun in forum 1.x Help
    Replies: 2
    Last Post: Apr 14, 2010, 8:19 PM
  4. Retrieve treepanel's root after reload
    By whitvanilla in forum 1.x Help
    Replies: 0
    Last Post: Jun 04, 2009, 9:28 AM
  5. [CLOSED] TreePanel + AjaxMethod + AsyncNode + Root
    By state in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: May 08, 2009, 8:01 AM

Posting Permissions