Horizontal Tree implementing onNodeRightClick($event, node)
I am writing an application and I need to have a context menu open up every time I right click a node in the horizontal tree. I took a look at the source code and I see that there are event emitters for when a node is selected and deselected among other things, but there is no emitter when a node is right-clicked. I was wondering if there is a way for me to add an event emitter that would fire when i right clicked a node in the tree?
-
- Posts: 449
- Joined: 08 Aug 2018, 14:09
Hi,hayksmn wrote: ↑21 Feb 2019, 13:03I am writing an application and I need to have a context menu open up every time I right click a node in the horizontal tree. I took a look at the source code and I see that there are event emitters for when a node is selected and deselected among other things, but there is no emitter when a node is right-clicked. I was wondering if there is a way for me to add an event emitter that would fire when i right clicked a node in the tree?
You can use onNodeContextMenuSelect and you can find more info in https://www.primefaces.org/primeng/#/tree .
Best Regards.
<p-tree [value]="dummyGraph2" layout="horizontal" selectionMode="single" [(selection)]="selectedFile3" (onNodeContextMenuSelect)="nodeRightClick($event, node)"></p-tree>
And the method:
nodeRightClick(event, node){
event.stopPropagation();
console.log(`event: ${event}`)
console.log(`node: ${node}`)
}
Does this look right? So far when I right click a node it just opens up the browser's default context menu. I also tried overriding the default behavior and then trying this but the callback function isn't called at all.
And the method:
nodeRightClick(event, node){
event.stopPropagation();
console.log(`event: ${event}`)
console.log(`node: ${node}`)
}
Does this look right? So far when I right click a node it just opens up the browser's default context menu. I also tried overriding the default behavior and then trying this but the callback function isn't called at all.
-
- Posts: 449
- Joined: 08 Aug 2018, 14:09
Hi,hayksmn wrote: ↑22 Feb 2019, 15:16<p-tree [value]="dummyGraph2" layout="horizontal" selectionMode="single" [(selection)]="selectedFile3" (onNodeContextMenuSelect)="nodeRightClick($event, node)"></p-tree>
And the method:
nodeRightClick(event, node){
event.stopPropagation();
console.log(`event: ${event}`)
console.log(`node: ${node}`)
}
Does this look right? So far when I right click a node it just opens up the browser's default context menu. I also tried overriding the default behavior and then trying this but the callback function isn't called at all.
You can use like this;
html;
Code: Select all
<p-tree [value]="filesTree6" selectionMode="single" (onNodeContextMenuSelect)="onRightClick($event)" [(selection)]="selectedFile2" [contextMenu]="cm"></p-tree>
<p-contextMenu #cm [model]="items"></p-contextMenu>
Code: Select all
onRightClick(event) {
console.log("event",event.originalEvent);
console.log("node", event.node)
}
-
- Information
-
Who is online
Users browsing this forum: No registered users and 25 guests