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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

TreeView ContextMenu. Get TreeNode value on TreeView while click ContextMenu

Thread ID:

Created:

Updated:

Platform:

Replies:

141939 Jan 11,2019 08:48 AM UTC Jan 14,2019 01:25 PM UTC Angular - EJ 2 1
loading
Tags: Treeview
Tin
Asked On January 11, 2019 08:48 AM UTC

Hi,

I am using ContextMenu component on my TreeView component, I want to add child for node using ContextMenu, I don't now how I can get the current id of  node on TreeView while I right click to add a child for it's node.

I using TreeView for Angular 7x

I try:

HTML:
<ejs-treeview id="treeMaterial" #treeMaterial [fields]="treeFields" [allowDragAndDrop]="true" (nodeExpanding)="nodeExpanding($event)" [loadOnDemand]="true"</ejs-treeview>

<ejs-contextmenu id='contextmenu' #contextmenu target='#treeMaterial' (beforeOpen)='beforeOpen($event)' [items]='menuItems'></ejs-contextmenu>`

TS:
I using beforeOpen
public beforeOpen(args: BeforeOpenCloseMenuEventArgs) {

        var node = $(args.event.target).closest("e-list-item e-level-3 e-active e-node-focus");

        ////???
    }


Thank so much !!!

Christopher Issac Sunder K [Syncfusion]
Replied On January 14, 2019 01:25 PM UTC

Hi Tin, 

Thank you for contacting Syncfusion support. 

In our TreeView component, we have selectedNodes property which stores the id of the selected tree nodes. You can use this property in the contextMenu beforeOpen event, to get the id of the tree node which was clicked using the below code, 
  
[HTML] 
<ejs-treeview id="treeMaterial" #treeMaterial [fields]="treeFields" [allowDragAndDrop]="true" (nodeExpanding)="nodeExpanding($event)" [loadOnDemand]="true"</ejs-treeview> 
<ejs-contextmenu id='contextmenu' #contextmenu target='#treeMaterial' (beforeOpen)='beforeOpen($event)' [items]='menuItems'></ejs-contextmenu> 
  
[TS] 
@ViewChild ('treeMaterial') treeView: TreeViewComponent; 
public beforeOpen(args: BeforeOpenCloseMenuEventArgs) { 
let treeId: string = this.treeView.selectedNodes[0]; 
We have prepared a sample for your reference.  

We have documented on how to add, remove and rename nodes using contextMenu in TreeView in our help site - https://ej2.syncfusion.com/angular/documentation/treeview/how-to/process-the-tree-node-operations-using-context-menu/ .  

Let us know if you have any more concerns. 

Thanks, 
Christo 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;