Several igTree methods require a node index to be specified, however, I cannot find in the documentation how to determine the index of any node.
Hello Ray,
After an investigation, I have determined that the path of the parent nodes represent the index. However, the child nodes could not be accessed by index. What I could suggest is accessing the node elements by value or by their path.
The path of a node could be accessed by using the nodeFromElement method. This could be achieved as follows:
var nodeObject = $("#tree").igTree("nodeFromElement", nodeElement);
var path = nodeObject.path;
Additionally, I have noticed that most of the igTree methods require the node element or the node object as an argument.
I have prepared a sample, demonstrating some of the igTree methods. Please test it on your side and let me know if you need any further information regarding this matter.
Regards, Monika Kirkova, Infragistics
Thank you for your response. Unfortunately, this does not address my situation. I am using the addNode method significantly to add a tree node to a parent node, but not always as the last child of the parent node. In this instance, the method requires the nodeIndex of the child node prior to which I want to insert a new node. For my situation I have determined a way to keep track of this for each node in my tree. However, along with the { path: "node_path", element: jQuery LI Element, data: data, binding: binding } that can be retrieved for each child node, it would be nice to include nodeIndex as one of the values rather than requiring a significant work around, which I put in place, to keep track of this for each child node.
I have been looking into your question and what I could say is that although the current methods do not return the exact index of the node, as my colleague has mentioned, the path of the nodes represents the indices.
For example, if we have an igTree with the following structure:
and we would like to get the index of the node with text "Brazil", we could use the findNodesByText method. The node object structure, as you have pointed out, is { path: "node_path", element: jQuery LI Element, data: data, binding: binding }, where the path represents the indices.
In this example
const targetNode = $("#tree").igTree("findNodesByText", "Brazil")[0];
the targetNode will be:
{path: '1_0', element: m.fn.init, data: {…}, binding: {…}}
where the path "1_0" means the first child (at index 0) of the second node at root level (at index 1).
Having this in mind, in order to get the index of the specified node, you could extract it from the path property (path: '1_0').
Here could be found a small sample demonstrating my suggestion where I have an igTree with the following structure:
and I am adding a child node between "New York" and "Boston".
This could be observed in the below attachment:
Please test this approach on your side and let me know if you need any further assistance regarding this matter.
Sincerely, Riva Ivanova Associate Software Developer