Results 1 to 2 of 2

Thread: Problem with .reload() on a leaf tree node

  1. #1
    Sencha User
    Join Date
    Sep 2008
    Location
    Germany
    Posts
    62

    Lightbulb Problem with .reload() on a leaf tree node

    Hello !

    I have a tree with a remote datasource. I have a function where I can add child elements to a tree node. This happens on server side. After the new entry in the database is created I use this:

    HTML Code:
    mytree.getNodeById(parent_id).reload();
    Of course the var parent_id contains the correct node_id. This works very well on nodes that already have children. On a leaf node this does not work. Can I manually set it on "not leaf" before reloading the tree? Or is the only way to use addChildNode?

    Greetz
    Achim

  2. #2
    Sencha User razvanioan's Avatar
    Join Date
    Feb 2008
    Location
    Romania
    Posts
    135

    Default

    Hello Achim,

    This was a though one for me as well, as I've struggled all this evening to find the best way to do it.
    The ideea is that 'leaf' nodes, normally do not need a load() method (as they do not have children, when first time loaded), and I wanted to be able to first add a child to it, and then reload (only that node).

    I've found two solutions, but last one fits my needs (where I'm using TreeLoader.load() method directly):

    Solution 1:
    After a successful add (to the server-side) I was returning the ID of the new generated node + I knew the text from the add form, so I added the node manually to the desired node (which was leaf before).

    PHP Code:
    if(node.isLeaf()){
      
    node.leaf false;
      
    node.setCls('folder');
    }

    node.appendChild(
      new 
    Ext.tree.AsyncTreeNode({
        
    cls'leaf',
        
    leaftrue,
        
    checkedfalse,
        
    idaction.result.new_id // sent from server,
        
    texttitle (from form text field or from server...)
      })
    )

    node.expand(); 
    Solution 2:
    As I wanted to still use server-side (re)load method, and don't remember if I still had some rendering issues with second added node or to nodes added to already rendered as folder nodes, I came up with this method instead. Also with the method above you can appendChildren only to the end of child nodes of a parent which may not always be the desired sorting.....

    PHP Code:
    // if leaf, add folder ui
    if(node.isLeaf()){
      
    node.leaf false;
      
    node.setCls('folder');
    }
                                    
    // if node was loaded as folder first time, use reload
    if(node.reload){
      
    node.reload();
    } else {
      
    // otherwyse, use TreeLoader.load() method, and force an expand when finished
      
    node.getLoader().load(node,function(node){
        
    node.expand();
      });


    Of course that here you can use even a more simple solution, but I've prefered to use reload() method for nodes which were loaded as 'folder' from start:
    PHP Code:
    // if leaf, add folder ui
    if(node.isLeaf()){
      
    node.leaf false;
      
    node.setCls('folder');
    }

    node.getLoader().load(node,function(node){
      
    node.expand();
    }); 
    It would have been nice to have an easy solution to swap (and add or remove all new functionality) node types from leaf to folder and vice-versa.

    Hope it helps,
    Razvan

Similar Threads

  1. Tree view problem node leaf
    By pearl_123 in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 29 Apr 2009, 4:54 PM
  2. Problem inserting a tree node into a tree as a non-leaf
    By FoxMulder900 in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 3 Dec 2008, 1:02 AM
  3. tree appendChild(node) to leaf, leaf status is not changed
    By vaalaskala in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 16 Apr 2008, 9:04 AM
  4. A strange problem of tree node 'leaf' attributes
    By enotsl in forum Ext 1.x: Help & Discussion
    Replies: 7
    Last Post: 17 Jul 2007, 10:35 PM

Posting Permissions

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