You found a bug! We've classified it as EXTJS-6525 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha Premium Member
    Join Date
    Jul 2011
    Posts
    18
    Vote Rating
    0
    jonas007 is on a distinguished road

      0  

    Default appendChild(Node) doesn't work correct in Ext 4.1

    appendChild(Node) doesn't work correct in Ext 4.1


    In my application some nodes are loaded when you click on another. All nodes are expandable. In my example, see below, the first node (added by children config property) is shown with expander but the second node (added by appendChildren) has no expander. In Ext 4.0 both nodes have an expander. How can I ensure that both nodes have an expander, even if they do not have any children?

    Code:
    var store = Ext.create('Ext.data.TreeStore', {    root: {
            expanded: true,
            children: [
                { text: "Node 1", expandable: true}
            ]
        }
    });
    
    
    store.tree.root.appendChild({text: "Node 2", expandable: true});
    
    
    Ext.create('Ext.tree.Panel', {
        title: 'Simple Tree',
        width: 200,
        height: 150,
        store: store,
        rootVisible: false,
        renderTo: Ext.getBody()
    });

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,159
    Vote Rating
    674
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    The reason this happens is because the node is a phantom. Since it doesn't have an id, it means it isn't created yet on the server, so it automatically assumes the node has been loaded.

    This is because you can't query the server to return any child nodes, because the server doesn't know about the phantom node yet.

    However, the logic should be the same whether you use appendChild or via the children property.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2011
    Posts
    18
    Vote Rating
    0
    jonas007 is on a distinguished road

      0  

    Default


    Thank you, my workaround ist to set phantom = false after creating the node. But indeed, the logic should be the same whether you use appendChild or via the children property.Thank you!

  4. #4
    Sencha User
    Join Date
    Sep 2012
    Posts
    2
    Vote Rating
    0
    dkomin is on a distinguished road

      0  

    Default


    It works if you set node.phantom = false; on beforeappend on TreeStore

  5. #5
    Sencha User
    Join Date
    Aug 2011
    Posts
    68
    Vote Rating
    2
    MaciejZabielski is on a distinguished road

      0  

    Default


    This is not entirely true. You only assume (for the developer) that he wants to add nodes on the client side. I have a function to locate required node somewhere deep in the tree. To avoid expanding each branch separately (and calling the server multiple times), I can load entire "subtree" from the server. Then I add it to the client tree using appendChild - where specific node is a "merge point".

    In that case all nodes are from the server, have ID's and everything they need, so setting them as "loaded" is not correct.