[CLOSED] How to set NodeID to newly added node via script

  1. #1

    [CLOSED] How to set NodeID to newly added node via script

    I have following code:
    function saveSearch(btn, text) {
            if (btn == 'ok')
                App.direct.SaveSearch(text, {
                    success: function (result) {
                        var store = App.TreePanel1.getStore();
                        node = store.getNodeById("savedSearches");
                        var childNode = node.appendChild({
                            internalId: "id_" + result,
                            text: result,
                            leaf: true,
                        })
                        alert(childNode.internalId)
                    }
                });
        };
    Internal ID (NodeID) alerted is different from what I have assigned to childNode.

    When I set NodeID via Razor, or code-behind it works. How to do it via script?
    Last edited by Daniil; Sep 15, 2015 at 7:12 AM. Reason: [CLOSED]
  2. #2
    Well I found it :)
    For further reference, somehow it does not work if you set it directly in append child. Rather you do it in setId method after you add child, like this:
    function saveSearch(btn, text) {
            if (btn == 'ok')
                App.direct.SaveSearch(text, {
                    success: function (result) {
                        var store = App.TreePanel1.getStore();
                        node = store.getNodeById("savedSearches");
                        var childNode = node.appendChild({
                            text: result,
                            leaf: true,
                        })
                        childNode.setId("id_" + result);
                    }
                });
        };
    Thanks
  3. #3
    Hi @ingbabic,

    Please try:
    node.appendChild({
        id: "id_" + result,
        text: result,
        leaf: true
    });
  4. #4
    That worked as well. I was trying to set internalId in script (as that is actual field name which should be set), but that didn't worked.
    Strange. You set id, but actual field which is changed is internalId. Not to mention that the same value in c# code is called NodeID :)
  5. #5
    Strange. You set id, but actual field which is changed is internalId.
    I beg to differ. A Node's id doesn't affect on its internalId in this test case.

    Example
    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v3 Example</title>
    
        <script>
            var test = function () {
                var newNode = App.TreePanel1.getRootNode().appendChild({
                    id: "someId",
                    text: "New Node",
                    leaf: true
                });
    
                Ext.Msg.alert("Comparison", "id: " + newNode.id + "<br>internalId: " + newNode.internalId);
            };
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Button runat="server" Text="Add node and compare its id and internalId" Handler="test" />
    
            <ext:TreePanel ID="TreePanel1" runat="server">
                <Root>
                    <ext:Node Text="Root" Expanded="true" />
                </Root>
            </ext:TreePanel>
        </form>
    </body>
    </html>
    Not to mention that the same value in c# code is called NodeID
    Agree, it might be confusing. To be honest I don't know for sure why it is NodeID rather than ID. Currently, I don't see any technical reason for this. My guess is that there was such a reason before not to call the property ID and later NodeID has been left for backwards compatibility. Maybe, the reason was to differ the property name from ASP.NET Control's ID property. Again, I don't know for sure. I'll ask one colleague. Maybe, he remembers. If he provide any new information on that rather than my guesses, I'll share. Anyways, most likely NodeID will be still left. At least, in Ext.NET v3.
  6. #6
    Well, when I try your sample, id of the node is internally assigned, but internalId is id that you have assigned, just as I said (see the picture)

    Click image for larger version. 

Name:	sample.png 
Views:	105 
Size:	17.1 KB 
ID:	24228

    But what is important to me is that my case is resolved. Thanks :)
  7. #7
    Sorry, I initially tested with Ext.NET v3 which produces another result.
    Click image for larger version. 

Name:	Node id.JPG 
Views:	110 
Size:	14.8 KB 
ID:	24232

    With v2 I am having the same you do. So, it has been changed in v3 and became more consistent.

    I'll ask one colleague. Maybe, he remembers. If he provide any new information on that rather than my guesses,
    It is about "NodeID vs ID". The colleague said that at some point there was a problem in Visual Studio which sort of dislikes the ID name of the property interpreting it like a Control's ID. Personally, I don't know if it is still actual in modern Visual Studios, but I guess we will leave NodeID for backwards compatibility anyways.

Similar Threads

  1. Obtain NodeID from parent node (nodeProxy)
    By sfedorov in forum 2.x Help
    Replies: 1
    Last Post: Jul 02, 2013, 8:51 PM
  2. [CLOSED] Get RecordID of Newly Added Row
    By hemantpatil in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Mar 15, 2013, 6:30 AM
  3. Edit the Newly added column in gridpanel
    By thota in forum 2.x Help
    Replies: 0
    Last Post: Dec 26, 2012, 11:02 AM
  4. [CLOSED] TreePanel with ContextMenu retrieve NodeID of node clicked
    By taylorjp2000 in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 13, 2012, 3:17 PM
  5. [CLOSED] How to set the ID of a newly added tree node
    By mattwoberts in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Jan 11, 2011, 7:34 AM

Tags for this Thread

Posting Permissions