[CLOSED] TreePanel Append node id

  1. #1

    [CLOSED] TreePanel Append node id

    Dear Support Members,

    on appending a new node how can i myself set id of that node by default it is auto generated.
    Last edited by Daniil; Nov 17, 2011 at 7:59 AM. Reason: [CLOSED]
  2. #2
    Hi,

    If you handle remote events in code behind, you can just set up its NodeID
    protected void RemoteAppend(object sender, RemoteAppendEventArgs e)
    {
        e.Accept = true;
        e.NodeID = "MyNodeId";
    }
    If in a WebService or a Controller Action, you should set up "response", like this:
    {
        "d" : {
            "success" : true,
            "response" : {
                "text" : "remoteText",
                "id"   : "remoteId"
            }
        }
    }
  3. #3
    Dear Daniil,
    I try your suggesions but they do not work,

    My Controller returns

    result.Data = new
                        {
                            d = new
                            {
                                success = true,
                                response = new
                                {
                                    text = text,
                                    id = savedLocation.Id
                                }
                            }
                        };
    and in firebug response is as follows

    {"d":{"success":true,"response":{"text":"New88888","id":29}}}
    but id is still "xnode-40".
    Last edited by Daniil; Nov 17, 2011 at 9:18 AM. Reason: Please use [CODE] tags
  4. #4
    It works for me. Here is my test case.

    Example View
    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!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.MVC Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            
            <ext:TreePanel 
                ID="TreePanel1"
                runat="server" 
                Height="300" 
                Width="250"
                Mode="Remote"
                RootVisible="false"
                RemoteJson="true"
                RemoteAppendUrl="/Test/RemoteAppend">
                <Loader>
                    <ext:TreeLoader DataUrl="/Test/GetNodes" Json="true" />
                </Loader>
                <Root>
                    <ext:AsyncTreeNode NodeID="0" Text="Root" />
                </Root>
                 <Editors>
                    <ext:TreeEditor runat="server">
                        <Field>
                            <ext:TextField runat="server" />
                        </Field>
                    </ext:TreeEditor>
                </Editors>
                <Listeners>
                    <RemoteActionSuccess Handler="alert(TreePanel1.getNodeById('NodeControllerId'));" />
                </Listeners>
            </ext:TreePanel>
            <ext:Button runat="server" Text="Append">
                <Listeners>
                    <Click Handler="TreePanel1.appendChild(TreePanel1.root.childNodes[0], '');" />
                </Listeners>
            </ext:Button>
        </form>
    </body>
    </html>
    Example Controller
    using System;
    using System.Web.Mvc;
    using Ext.Net;
    using Ext.Net.MVC;
    
    namespace Mvc.Controllers
    {
        public class TestController : Controller
        {
    
            public ContentResult GetNodes(string node)
            {
                TreeNodeCollection nodes = new TreeNodeCollection(false);
    
                string prefix = DateTime.Now.Second + "_";
                for (int i = 0; i < 10; i++)
                {
                    Ext.Net.TreeNode newNode = new Ext.Net.TreeNode();
                    newNode.NodeID = i.ToString();
                    newNode.Text = prefix + i;
                    newNode.Leaf = true;
                    nodes.Add(newNode);
                }
    
                return Content(nodes.ToJson());
            }
    
            public JsonResult RemoteAppend()
            {
                JsonResult r = new JsonResult();
                r.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
                r.Data = new
                {
                    d = new
                    {
                        actionSuccess = true,
                        response = new
                        {
                            text = "Hello from Controller!",
                            id = "NodeControllerId"
                        }
                    }
                };
    
                return r;
            }
        }
    }
    Steps:

    1. Click on the Append button
    2. Press Enter
    3. An alert message appears with a node retrieved by the TreePanel's getNodeById method.
  5. #5
    Dear Daniil,

    I tried Your test case, on my side alert apears with message undefined only when i replace 'actionSuccess' to 'success' in controller.
  6. #6
    Well, could you update from SVN and re-test?

    I've just tried again - it works fine on my side.
  7. #7
    Well How can I update from Svn can you plz guid me
  8. #8

Similar Threads

  1. [CLOSED] Append a fully loaded child in a remote TreePanel
    By RCN in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: May 30, 2012, 12:23 PM
  2. How to get Node by id in treepanel 2.0?
    By tms2003@126.com in forum 2.x Help
    Replies: 1
    Last Post: Apr 03, 2012, 3:01 PM
  3. Treepanel Node
    By lindgrenm in forum 1.x Help
    Replies: 0
    Last Post: Feb 10, 2010, 3:08 PM
  4. [CLOSED] [1.0] TreePanel add node at DirectEvent
    By methode in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 08, 2009, 1:56 PM
  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

Posting Permissions