i'm trying to add buttons in certain columns of my p-table,
actually i'm doing that in my html:
<p-table [columns]="cols2" [value]="subflows">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" [ngStyle]="{'width': col.width}" [ngClass]='height'>
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [ngClass]="rowData.type ==='ERROR' ? 'red' : 'blue'">
<td class="my-center-text" *ngFor="let col of columns; let i = index"
[attr.rowspan]="rowData.component.index === 1 ? 2 : 1"
[ngClass]="{'center' : (col.field ==='detail' || col.field ==='objet' || col.field ==='messageT' || col.field === 'etape')}">
{{rowData[col.field]}}
<!-- <p-column field="detail" header="" [style]="{'text-align':'center'}">
<ng-template let-row="rowData" pTemplate="body">
<button pButton style="height:30px;" label="Détails"
(click)="show(rowData, i)" class="ui-button-secondary"></button>
</ng-template>
</p-column> -->
<button pButton style="height:30px;" *ngIf="col.field === 'detail' " label="Détails"
(click)="show(rowData)" class="ui-button-secondary"></button>
<button pButton style="height:30px;" icon="pi pi-search" *ngIf="col.field === 'objet' "
(click)="objet($event,data)" class="ui-button-secondary"></button>
<button pButton style="height:30px;" icon="pi pi-search" *ngIf="col.field === 'messageT' "
(click)="checked($event,data)" class="ui-button-secondary"></button>
</td>
</tr>
</ng-template>
</p-table>
I'm not sure its the best way to do it and i actually have one problem which is, my button is related to a p-dialog and actually, when i click on a button, the first one is opening a p-dialog, but if i click again on another button, data is directly added to the existing p-dialog, i want it to open a new p-dialog for everynew button i click.
I have used this once. You just need to use the content
property of the column definition. Like this
{
headerText:'Action',
content: function(row) {
return $("<button></button>").puibutton({
icon: 'ui-icon-pencil'
});
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.