0

I have created a tree panel by specifying the xtype as treecolumn. I want to select the first leaf of the tree. In this example I have registered the boxready event detailed below:

boxready : function( treePanel, width, height, eOpts ){

    treePanel.getSelectionModel().select( 0 );
    //treePanel.select( treePanel.getRootNode().getChildAt(0) );
    treePanel.getSelectionModel().selected = 0;
},
treePanel.getSelectionModel()

This example is giving me selectionmodel of type SINGLE. Can anyone explain why my example does not select the first leaf?

Reimius
  • 5,694
  • 5
  • 24
  • 42
user2211050
  • 139
  • 1
  • 10

1 Answers1

0

This is a little "diagram":

If you need the leaf from beginning with:

  • one node selected:

    var nodeData = treePanel.getSelectionModel().getSelection();

  • from the begin:

    var node = treePanel.getRootNode(); -- father ( first Node );

    findLeaf : function(node){

    if(node.isLeaf()){
    // this is the node that u want
    }else{
        // bucle to find it
        node.eachChild(function(nodeChild,array){
            if(nodeChild.isLeaf()){
               // this is the node that u want
            }else{
               // get childs of this node
               if(nodeChild.hasChildNodes()){
                    //find the childs from this node.
                    this.findLeaf(nodeChild);
               }
            }
        });
    }
    

    };

mfruizs
  • 770
  • 14
  • 20
  • In my case there is no node selected, so i got the node by var node = treePanel.getRootNode(); but inside the component i got childNodes of 0 items so it is not going to foreach loop. can you please tell me where am missing ? – user2211050 Apr 02 '13 at 12:47
  • If u didnt select one, you need to get the root node. Maybe, u can get it from the tree store. but im thinking that ur store its empty, that the error... – mfruizs Apr 02 '13 at 14:05
  • Yes you are right. at that time time the store was empty. so i moved the code to store.onload, and now its working fine. – user2211050 Apr 04 '13 at 05:05