getBranchIndex

gets index of the node in a specific branch

number getBranchIndex(id id, [id parent] );

Parameters

ididtree node ID
parentidoptional, ID of the parent node

Returns

numberindex of related tree node

Example

var tree = webix.ui({
    view:"tree",
    data: [
        { id:"branch1", value:"The Shawshank Redemption", data:[
            { id:"1.1", value:"Part 1" },
            { id:"1.2", value:"Part 2" }
        ]}
    ]
});
 
var index  = tree.getBranchIndex("1.1"); // -> 0
var index1 = tree.getBranchIndex("1.2"); // -> 1

Details

There is also the getIndexById method to get the node index, but we don't suggest using it. It's a common method that is inherited by all data-containing components from the DataStore class and not intended for using with tree-like data structures.

For exact node specifying, pass both node ID and parent node ID into the function:

var sel = tree.getSelectedId(); 
var parent = tree.getParentId(sel); 
tree.add({ value:"New item"}, tree.data.getBranchIndex(sel, parent), parent);
See also
Back to top
If you have not checked yet, be sure to visit site of our main product Webix html5 ui library and page of tree grid ui product.