We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Can get node fullPath with nodeClick?

Hello,

I´m trying to get the fullnode path of a node; for example:

1.First_Level
     1.1. Second_Level_1
     1.2. Second_Level_2
          1.2.1 Third_Level_1
     1.3. Second_Level_3

Imagine that I click on 1.2.1, what I want to get is the path: First_Level/Second_Level_2/Third_level_1

Can I do this?

Thank your very much.

3 Replies

CI Christopher Issac Sunder K Syncfusion Team December 12, 2018 12:33 PM UTC

Hi Jon Andoni, 

Thank you for contacting Syncfusion support. 

In our TreeView component, we have provided the option to get the node data for specified tree node element. You can use this method to get the full path for corresponding node click action. Please check the below code logic. 

public parentNodes: any = []; 
//Node Selected Event for TreeView component 
public onNodeSelected(args: NodeSelectEventArgs): void { 
    this.parentNodes.push(args.node) 
    this.findParentNodes(args.node); 
    let fullpath = ""; 
    for(let i = this.parentNodes.length - 1; i >= 0; --i) { 
        //using getNode method to get the node text 
        var data = this.tree.getNode(this.parentNodes[i]); 
        fullpath = fullpath + data.text; 
        if (i != 0) { 
            fullpath = fullpath + '\\'; 
        } 
    } 
    alert(fullpath); 
    this.parentNodes = []; 
  } 
  //collect the parent nodes for currently selected node 
  public findParentNodes(node: HTMLElement) { 
    let parent: HTMLElement = node.parentElement.parentElement; 
    if (parent.classList.contains("e-list-item")) { 
        this.parentNodes.push(parent); 
        this.findParentNodes(parent); 
    } 
} 


Please let us know if you require any further assistance. 

Thanks, 
Christo


JA Jon Andoni December 17, 2018 12:54 PM UTC

Hello,

It works,

Thanks Christo.


CI Christopher Issac Sunder K Syncfusion Team December 18, 2018 05:17 AM UTC

Hi Jon Andoni, 

We are glad to hear that the issue has been resolved at your end. Please let us know if you require further assistance. 

Thanks,
Christo 


Loader.
Live Chat Icon For mobile
Up arrow icon