Results 1 to 7 of 7

Thread: treePanel.getNodeById() not working after changing node.id

  1. #1

    Default treePanel.getNodeById() not working after changing node.id

    Here's the problem...
    I'm creating a new node in the tree dynamically, then using treeEditor to let the user edit the node test, and once they finish entering the text, I use an AJAX hook in my app to store the new node in the database. Using the AJAX results, I change the ID of the node to its ID in the database.

    When I do this, tree.getNodeById(newID) returns 'undefined'.

    Is this a bug?

  2. #2
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966

    Default

    You can't simply change the node.id without updating the tree.nodeHash:

    Code:
    function changeNodeID(node,id){
       if(node){
          var tree = node.getOwnerTree();
          if(tree){
             tree.unregisterNode(node);
             node.id  = id;
             tree.registerNode(node);
          }
       }
    
    }
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  3. #3

    Default

    Thanks a lot, I'll try that right now.

    Is that behaviour documented anywhere? All I see in the API doc is that 'id' is a public property, so I figured it would be fine to change it.

    Is there any documentation on the tree and tree widgets and how they interact other than the API doc?


    Xavier

  4. #4
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966

    Default

    No and No.
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  5. #5
    Sencha User
    Join Date
    Apr 2008
    Posts
    365

    Default

    Thanks hendricd for sharing this code. I'm trying to do the same but I got a problem: After changing the id of a node like showed above, the node is somehow "undefined": For example when you mouseover it, I get this error:

    node is undefined
    onNodeOver()(Object browserEvent=Event mouseout button=0 type=mouseout, undefined)ext-all-debug.js (Linie 23730)
    delegateOver()(Object browserEvent=Event mouseout button=0 type=mouseout, div#extdd-40.x-tree-node-el)ext-all-debug.js (Linie 23693)
    h()()ext-all-debug.js (Linie 1723)
    apply()()ext-base.js (Linie 9)
    [Break on this error] node.ui.onOver(e);

    Any idea what could be wrong?

    Added: It seems that the tree-node-id of the surrounding div of each treenode is note updated. Any smart way to do this?

  6. #6
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966

    Talking

    @wuschba -- I'd forgotten all about you Drag-Droppers.

    Try this variant:

    Code:
    Ext.override ( Ext.tree.TreeNode , {
      changeID: function(id){
       if(id){
          var tree = this.getOwnerTree();
          if(tree){
             tree.unregisterNode(this);
             this.onIdChange(this.id  = id);
             tree.registerNode(this);
          }
       }
    
      },
      // private
      onIdChange: function(id){
         id = id || this.id;
         if(this.ui.onIdChange){  //Ext 3.0 support.
            this.ui.onIdChange(id);
            return;
         }
         //Ext 2.x
         this.ui.rendered && this.ui.elNode.setAttribute('ext:tree-node-id', id);
      }
    });
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  7. #7
    Ext JS Premium Member
    Join Date
    Feb 2008
    Posts
    17

    Default

    Quote Originally Posted by hendricd View Post
    You can't simply change the node.id without updating the tree.nodeHash:

    Code:
    function changeNodeID(node,id){
       if(node){
          var tree = node.getOwnerTree();
          if(tree){
             tree.unregisterNode(node);
             node.id  = id;
             tree.registerNode(node);
          }
       }
    
    }
    Didn't work for me, because after that the node is not selectable.
    This is how I got it working now:

    Code:
    var node = tree.getSelectionModel().getSelectedNode();
    node.setId(result.data.id);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •