Show Context Menu after condition Check in Primeng Angular 4

女生的网名这么多〃 提交于 2019-12-08 06:44:54

问题


I have to show a context menu in a primeng tree table only in the second level. Is there any way to show the context menu only after some condition check in typescript (angular 4)?


回答1:


you can bind onContextMenuSelect event and play with [hide], I have done it like this.. in html...

  <p-contextMenu #cm [model]="items" [hidden]="contextMenu"></p-contextMenu>

and in ts ..

viewDetails(selectedNode) {
    this.contextMenu = false;
    if (selectedNode.children.length == 0) {
        this.contextMenu = false;
    }
    else { this.contextMenu = true;}
}

hope it works..




回答2:


For me, the best option was to use onContextMenuSelectEvent. First, you need to add it to the tree table

<p-treeTable [style]="{'font-size':'1.7rem'}" selectionMode="single" [(selection)]="selectedFile" (onContextMenuSelect)="contextMenu($event.node, cm)" [contextMenu]="cm" [value]="treeNodeData">

and then in the method, you have to check your conditions and show or hide context menu

  contextMenu(node, contextMenu){
if(condition){
  contextMenu.hide();
  }
}

I hope that it will also work for you.



来源:https://stackoverflow.com/questions/47235291/show-context-menu-after-condition-check-in-primeng-angular-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!