Question

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?

Was it helpful?

Solution

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);
               }
            }
        });
    }
    

    };

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top