[Get node data on node selected]

Hello,

I'm using a treeview control and I populate it with the following hierarchical data:

Image_5187_1702802784791

So each node has the following data model:

nodeId: string;

idFunction: string;

nodeText: string;

iconCss: string;

redirectInfo: RedirectInfo


where RedirectInfo is another model which contains some data used when the user clicks on a specific node, in order to navigate to another component.


The issue occurs when I click on a specific node, using the (nodeSelecting) event:
Image_3049_1702802935517

The $event data doesn't contain all the neccessary data that was added in the node model, it contains only the following:

Image_7471_1702803178149
I need to have in nodeData all the properties from the hierarchical data, like children, redirectInfo and so on.

This is the fields property assigned to the tree when the remote data arrives in the component:

Image_1921_1702803337036

How to add/access all the properties in the nodeData property from the $event?


1 Reply

SA SureshRajan Alagarsamy Syncfusion Team December 18, 2023 08:09 AM UTC

Hi Ciprian,


We have reviewed your query and understand that you are looking to fetch the selected node details in the TreeView component. Also we have examined the shared screenshot, we would like to inform you that the “nodeSelecting” event arguments contain specific properties related to the selected node. To retrieve the entire set of node details, we recommend utilizing the "getTreeData" API method. This method will allow you to retrieve the complete datasource for the selected node.


Refer to the below code snippet for further reference.


[app.component.html]

 

<ejs-treeview

  #treeObj

  id="default"

  [fields]="field"

  (nodeSelecting)="OnNodeSelecting($event)"

></ejs-treeview>

 


[app.component.ts]

 

....

 

OnNodeSelecting(args: NodeSelectEventArgs) {

  var nodeDetails = this.treeObj.getTreeData((args.nodeData as any).id);

  console.log(nodeDetails);

}

 


We have also attached a sample for your reference.


Sample : https://stackblitz.com/edit/angular-p2ukln-epco1s?file=src%2Fapp.component.ts


Regards,
Suresh.


Loader.
Up arrow icon