[CLOSED] How to load treepanel with httphandler with selected node?

  1. #1

    [CLOSED] How to load treepanel with httphandler with selected node?

    I am loading a treepanel via ajaxproxy and hitting an url that's a httphandler. In the httphandler, I am sending back the NodeCollection.ToJson() to populate the tree. Is it possible to also send back the selected node? Or do I need to do another request?
    Last edited by Daniil; Dec 18, 2013 at 2:51 AM. Reason: [CLOSED]
  2. #2
    Hello!

    I think it's not possible but you can do it without extra request. You need to mark required nodes as selected and listen Load event:

    <ext:TreePanel 
        ID="TreePanel1" 
        runat="server" 
        Title="Tree" 
        Height="500"
        Width="200"
        Border="false">
        <Store>
            <ext:TreeStore runat="server">
                <Proxy>
                    <ext:AjaxProxy Url="TreeLoader.ashx" />
                </Proxy>
                <Listeners>
                    <Load Handler="
                        records.forEach(function(record) { 
                        if (record.get('selected')) 
                            App.TreePanel1.getSelectionModel().select(record); 
                        })"/>
                </Listeners>
            </ext:TreeStore>
        </Store>
        <Root>
            <ext:Node NodeID="0" Text="Root" />
        </Root>
    </ext:TreePanel>
    TreeLoader.ashx
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/json";
        string nodeId = context.Request["node"];
    
        if (!string.IsNullOrEmpty(nodeId))
        {
            NodeCollection nodes = new NodeCollection(false);
    
            for (int i = 1; i < 6; i++)
            {
                Node asyncNode = new Node();
                asyncNode.Text = nodeId + i;
                asyncNode.NodeID = nodeId + i;
                nodes.Add(asyncNode);
            }
    
            for (int i = 6; i < 11; i++)
            {
                Node node = new Node();
                node.Text = nodeId + i;
                node.NodeID = nodeId + i;
                node.Leaf = true;
                nodes.Add(node);
            }
            nodes[0].CustomAttributes.Add(new ConfigItem("selected", "true", ParameterMode.Raw));
            context.Response.Write(nodes.ToJson());
            context.Response.End();
        }
    }

Similar Threads

  1. Replies: 4
    Last Post: Mar 22, 2015, 4:04 PM
  2. TreePanel, get selected node
    By fatnjazzy in forum 2.x Help
    Replies: 7
    Last Post: Sep 12, 2013, 7:31 AM
  3. Replies: 11
    Last Post: Feb 06, 2013, 5:09 PM
  4. Selected Node Id of a TreePanel
    By Z in forum 1.x Help
    Replies: 1
    Last Post: Jul 21, 2010, 8:26 AM
  5. Treepanel - Set Selected Node
    By Tbaseflug in forum 1.x Help
    Replies: 2
    Last Post: Dec 01, 2009, 4:46 PM

Posting Permissions