Horizontal Tree implementing onNodeRightClick($event, node)

UI Components for Angular
Post Reply
hayksmn
Posts: 4
Joined: 21 Feb 2019, 13:00

21 Feb 2019, 13:03

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?

yigitfindikli
Posts: 449
Joined: 08 Aug 2018, 14:09

21 Feb 2019, 14:53

hayksmn wrote:
21 Feb 2019, 13:03
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?
Hi,
You can use onNodeContextMenuSelect and you can find more info in https://www.primefaces.org/primeng/#/tree .

Best Regards.

hayksmn
Posts: 4
Joined: 21 Feb 2019, 13:00

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.

yigitfindikli
Posts: 449
Joined: 08 Aug 2018, 14:09

22 Feb 2019, 17:15

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.
Hi,

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>
component;

Code: Select all

onRightClick(event) {
        console.log("event",event.originalEvent);
        console.log("node", event.node)
    }
Best Regards.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests