cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the first node of a tree as selected by default

SandipAgarwalla
Active Contributor
0 Kudos

Hi

How do i set the first node of the tree by default? I want to set the first node of the tree to be selected

I tried , yardTree.fireSelect("node"); but it didnt work out

var yardTree = new sap.ui.commons.Tree({
.....

select : [ function(oEvent) {

var control = oEvent.getSource();

var nodeId = oEvent.getParameter("node").getId();

//alert("nodeId::"+nodeId);

var selectedYardNo = oEvent.getParameter("node").getText();

//alert("selectedYardNo::"+selectedYardNo);

//call the odata

}, this ]

});

yardTree.setModel(jsonTreeModel);

for(var i=0;i<noOfNodes;i++){

var yardNo = oData.results[i].YardNo;

var node = new sap.ui.commons.TreeNode();

node.setText(yardNo);
//
    yardTree.addNode(node);

}

//selec the first node of the tree by default
//
var nodes [] = yardTree.getNodes();
//
yardTree.fireSelect(nodes[0]);
//

Any help?

Thanks

Sandip

Accepted Solutions (1)

Accepted Solutions (1)

former_member91307
Contributor
0 Kudos

Hi Sandip,

Parameter type for method 'fireSelect' is an object.

Instead of statement

'yardTree.fireSelect(nodes[0]); '

use 

var map = {};

map.node = nodes[0];

yardTree.fireSelect(map);

Thanks and Regards, Venkatesh

Answers (0)