2017-07-13 7 views
1

J'ai le code suivant:Primeng (angulaire 4): Le ContextMenu apparaît dans une autre position

<p-dataTable [contextMenu]="cm" [value]="Usuarios" selectionMode="single" [(selection)]="selectedRecord" resizableColumns="true" [rows]="10" [paginator]="true" [pageLinks]="3" [rowsPerPageOptions]="[5,10,20]" scrollable="true" scrollWidth="100%"> 
     <p-column [sortable]="true" field="id" header="ID" [style]="{'width':'50px'}"></p-column> 
     <p-column [sortable]="true" field="dni" header="DNI" [style]="{'width':'80px'}"></p-column> 
     <p-column [sortable]="true" field="ap_paterno" header="Apellido Paterno" [style]="{'width':'120px'}"></p-column> 
     <p-column [sortable]="true" field="ap_materno" header="Apellido Materno" [style]="{'width':'120px'}"></p-column> 
     <p-column [sortable]="true" field="nombres" header="Nombres" [style]="{'width':'120px'}"></p-column> 
     <p-column [sortable]="true" field="fecnac" header="Fecha de Nac" [style]="{'width':'150px'}"></p-column> 
     <p-column [sortable]="true" field="est_civil" header="Estado Civil" [style]="{'width':'120px'}"></p-column> 
     <p-column [sortable]="true" field="fec_ingreso" header="Fecha de Ingreso" [style]="{'width':'120px'}"></p-column> 
     <p-column [sortable]="true" field="movil" header="Movil" [style]="{'width':'100px'}"></p-column> 
     <p-column [sortable]="true" field="fijo" header="Fijo" [style]="{'width':'90px'}"></p-column> 
     <p-column [sortable]="true" field="direccion" header="Dirección" [style]="{'width':'180px'}"></p-column> 
     <p-column [sortable]="true" field="distrito" header="Distrito" [style]="{'width':'200px'}"></p-column> 
     <p-column [sortable]="true" field="email_corp" header="Email corporativo" [style]="{'width':'180px'}"></p-column> 
     <p-column [sortable]="true" field="email_per" header="Email personal" [style]="{'width':'180px'}"></p-column> 
     <p-column [sortable]="true" field="login" header="Login" [style]="{'width':'120px'}"></p-column> 
     <p-column [sortable]="true" field="contacto_emergencia" header="Contacto de emergencia" [style]="{'width':'180px'}"></p-column> 
     <p-column [sortable]="true" field="telef_contacto" header="Teléfono de Contacto" [style]="{'width':'100px'}"></p-column> 
     <p-column [sortable]="true" field="perfil" header="Perfil" [style]="{'width':'120px'}"></p-column> 
     <p-column [sortable]="true" field="turno" header="Turno" [style]="{'width':'120px'}"></p-column> 
</p-dataTable> 
<p-contextMenu #cm [model]="items"></p-contextMenu> 

Et je la question suivante: Lorsque je sélectionne un enregistrement, cela est mis en évidence comme sélectionné, mais son contexte menu apparaît loin. enter image description here

+0

Il suffit de regarder la vitrine pour contextMenu, avez-vous regardé en utilisant la propriété cible du contextMenu? Cela vous permet d'assigner un template var comme "anchor" du contextMenu. Cela pourrait aider. Une autre chose qui pourrait aider à isoler si c'est quelque chose que vous avez fait, vs quelque chose qui ne va pas avec le composant, est d'utiliser un plunkr pour tester votre code. [link] (http://plnkr.co/edit/Qi2Nw2imLpDUF8NJinYw?p=preview) – BillF

Répondre

4

Vous devez ajouter appendTo = « corps » à p-contextMenu comme celui-ci

<p-contextMenu #cm [model]="items" appendTo="body" ></p-contextMenu> 
+0

Parfait, fonctionne comme un charme !!! – user1892203