To customize the context menu options in your web page, you must include a Context Menu instance in your HTML code.
With the Context Menu, you can handle events using the command
specified in the items
array or utilize onNodeContextMenuSelect
.
For a demonstration, refer to this example: here
Add the following lines to your .html
file:
<p-tree
[value]="files"
selectionMode="single"
[contextMenu]="cm"
(onNodeContextMenuSelect)=showContect($event)
>
</p-tree>
<p-contextMenu
#cm
[model]="items"
>
</p-contextMenu>
Include these lines in your .ts
file:
ngOnInit() {
this.items = [
{
label: 'View',
icon: 'pi pi-search',
command: (event) => this.viewFile(this.selectedFile),
},
{
label: 'Unselect',
icon: 'pi pi-times',
command: (event) => this.unselectFile(),
},
];
}
showContect(event: any) {
console.log(event.node);
}