1. #1
    Ext JS Premium Member roman.savko's Avatar
    Join Date
    Mar 2011
    Location
    Kiev
    Posts
    26
    Vote Rating
    2
    roman.savko is on a distinguished road

      0  

    Default Treestore: load nodes but not expand all. How?

    Treestore: load nodes but not expand all. How?


    Hello everybody!
    I need your help: I have a treestore configured with Ajax proxy. RootNode is expanded, but child nodes are not. I want when tree is shown, treestore load ALL nodes, but not expand them. So when root node loads it childs, every child node loads it own childs... but they are collapsed.
    How I can achieve this?

    Thanks

  2. #2
    Sencha User
    Join Date
    Dec 2009
    Location
    Enschede, The Netherlands
    Posts
    327
    Vote Rating
    13
    flanders will become famous soon enough

      0  

    Default


    Can't you load all the data at once? Tree's can be loaded with all data once in a recursive style.

  3. #3
    Ext JS Premium Member roman.savko's Avatar
    Join Date
    Mar 2011
    Location
    Kiev
    Posts
    26
    Vote Rating
    2
    roman.savko is on a distinguished road

      0  

    Default


    Tree uses ajax proxy, which loads child nodes after node is being expanded. I need that when tree is loaded, it also loaded all childs.

  4. #4
    Sencha User
    Join Date
    Dec 2009
    Location
    Enschede, The Netherlands
    Posts
    327
    Vote Rating
    13
    flanders will become famous soon enough

      0  

    Default


    Okay, but tree's support this (in JSON)

    Code:
    {
      success: true,
      nodes: [{
      },{
        text: 'aap',
        nodes: [{
          text: 'bier',
          nodes: [{
          }]
        },{
        }]
      }]
    }
    This way you can load all nodes in one request. When specifying the properties of the children you can specify your 'rootProperty' again to specify the childnodes. This way you can recursivly deliver the whole tree at once

  5. #5
    Ext JS Premium Member roman.savko's Avatar
    Join Date
    Mar 2011
    Location
    Kiev
    Posts
    26
    Vote Rating
    2
    roman.savko is on a distinguished road

      0  

    Default


    That works fine if you have static child nodes or you know their quantity. In my case I set the root node, which contains url for its child nodes. And every child node has its own url to it childs. when root node expands, I read url for it childs, proxy via ajax receives response (json) and builds child nodes in tree.

  6. #6
    Ext JS Premium Member roman.savko's Avatar
    Join Date
    Mar 2011
    Location
    Kiev
    Posts
    26
    Vote Rating
    2
    roman.savko is on a distinguished road

      0  

    Default


    Fix which did all I needed:
    Code:
    store.on('load', function(store, node) {       
        Ext.each(node.childNodes, function (item, index, allItems) {
                if(!item.isLoaded() && !item.isLeaf()) {
                    store.load({node: item});
                }
            });
        });

  7. #7
    Ext JS Premium Member troseberry's Avatar
    Join Date
    Feb 2010
    Location
    Dayton, OH
    Posts
    277
    Vote Rating
    9
    troseberry will become famous soon enough

      0  

    Default


    Could you share your full code on the tree, store, and models. I have a similar issue where each node has an association model that has its own proxy and I am trying to figure out how to connect these things together.

Thread Participants: 2