reselect node in treepanel after page reload

Page 3 of 3 FirstFirst 123
  1. #21
    How can I indicate parent node for new created node ?
                        AsyncTreeNode asyncNode = new AsyncTreeNode();
                        asyncNode.Text = row["EQP_NAME"].ToString();
                        asyncNode.NodeID = row["EQP_ID"].ToString();
                        e.Nodes.Add(asyncNode);
    I try to do this
                        asyncNode.ParentNode = ParentNode; // this is parent node Ext.Net.TreeNodeBase type
    but this is not work
  2. #22
    Hope the following sample helps you, see the comments.

    Example

    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                object o = this.Session["selection"];
                if (o != null)
                {
                    string id = o.ToString();
                    if (id == this.TreePanel1.Root[0].NodeID)
                    {
                        this.TreePanel1.CallNode("select", id);
                    }
                    else
                    {
                        string handler = String.Format("onRender(this, '{0}');", id);
                        this.TreePanel1.Listeners.Render.Handler = handler;
                    }
                }
            }
        }
         
        protected void NodeLoad(object sender, NodeLoadEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.NodeID))
            {
                string nodeIdToSelect = e.ExtraParams["nodeIdToSelect"];
                if (nodeIdToSelect != null)
                {
                    //Here you need to implement adding respective nodes 
                    string msg = String.Format("You should add respective nodes to select '{0}' node", nodeIdToSelect);
                    X.Msg.Alert("Not implemented", msg).Show();
    
                    //this.DefaultSelectionModel1.Select(nodeIdToSelect);
                        
                }
                else
                {
                    for (int i = 1; i < 6; i++)
                    {
                        AsyncTreeNode asyncNode = new AsyncTreeNode();
                        asyncNode.Text = e.NodeID + i;
                        asyncNode.NodeID = e.NodeID + i;
                        e.Nodes.Add(asyncNode);
                    }
    
                    for (int i = 6; i < 11; i++)
                    {
                        Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
                        treeNode.Text = e.NodeID + i;
                        treeNode.NodeID = e.NodeID + i;
                        treeNode.Leaf = true;
                        e.Nodes.Add(treeNode);
                    }
                }
            }
        }
     
        [DirectMethod]
        public void SaveSelection(string id)
        {
            this.Session["selection"] = id; 
        }
    </script>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
     
        <script type="text/javascript">
            var onAppend = function (tree, node, nodeIdToSelect) {
                if (!tree.restoreSelectionLock) {
                    if (node.id === nodeIdToSelect) {
                        tree.getSelectionModel().select(node);
                        tree.restoreSelectionLock = true;
                    }
                }
            };
    
            var onSelectionChange = function (node) {
                //here you can save parent nodes ids as well
                //to access a parent node use node.parentNode
                Ext.net.DirectMethods.SaveSelection(node.id);
            };
    
            var onRender = function (tree, nodeId) {
                tree.loader.on(
                    "beforeload", 
                    function (loader) {
                        if (!loader.baseParams) {
                            loader.baseParams = {};
                        };
                        Ext.apply(loader.baseParams, { "nodeIdToSelect": nodeId });
                    },
                    null,
                    {
                        single : true
                    });
    
                tree.getRootNode().expand();
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
             
            <ext:TreePanel
                ID="TreePanel1"
                runat="server"
                Title="Tree"
                AutoHeight="true"
                Border="false">
                <Loader>
                    <ext:PageTreeLoader OnNodeLoad="NodeLoad" />
                </Loader>
                <Root>
                    <ext:AsyncTreeNode NodeID="0" Text="Root" />
                </Root>
                <SelectionModel>
                    <ext:DefaultSelectionModel ID="DefaultSelectionModel1" runat="server" >
                        <Listeners>
                            <SelectionChange Handler="onSelectionChange(node);" />
                        </Listeners>
                    </ext:DefaultSelectionModel>
                </SelectionModel>
            </ext:TreePanel>       
        </form>
    </body>
    </html>
  3. #23
    ok. now test it.
  4. #24
    This is not something that I have and ... after page reload root node does not open.

    The promlem is to load all tree and after that select (and expand) saved node (by saved node id).
  5. #25
    Did you read the comments?
  6. #26
    Quote Originally Posted by Daniil View Post
    Did you read the comments?
    Yes. This is the problem.
    I don't understand:
    - how to load all tree in treepanel
    - and after that select saved node.

    TreePanel1.CallNode("select", id) is not work. If I use this method, then I have an error.
  7. #27
    Quote Originally Posted by ginsar View Post
    - how to load all tree in treepanel
    Do you see how nodes are added in NodeLoad?

    Not sure what exactly problem you have.

    Just add respective nodes into Nodes collection.

    Please note that each node has .Nodes collection.

    Quote Originally Posted by ginsar View Post
    TreePanel1.CallNode("select", id) is not work. If I use this method, then I have an error.
    I did not use this code in my last example.
  8. #28
    If i just add respective nodes into Nodes collection, then I lost tree... and I will have only 1 level of tree.
    I should add nodes into Nodes collection with an indication of the parent or child
Page 3 of 3 FirstFirst 123

Similar Threads

  1. [CLOSED] Reload tree node
    By RCN in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: May 16, 2012, 8:39 PM
  2. [CLOSED] [1.0] Tree node reload is very slow
    By acrossdev in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Oct 28, 2010, 8:48 AM
  3. TreePanel.Reload
    By ankit in forum 1.x Help
    Replies: 0
    Last Post: Jun 11, 2010, 7:05 AM
  4. Reload TreePanel
    By Maia in forum 1.x Help
    Replies: 1
    Last Post: Jan 07, 2010, 4:39 AM
  5. TreePanel:Copying from one node to another node using drag and drop
    By eighty20 in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 25, 2009, 7:48 AM

Tags for this Thread

Posting Permissions