Skip to Content

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

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    Posted on Aug 21, 2013 at 07:58 AM

    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

    Add comment
    10|10000 characters needed characters exceeded