Add button to column of a p-table

UI Components for Angular
Post Reply
dallincha
Posts: 1
Joined: 03 Jul 2020, 11:25

03 Jul 2020, 11:28

Hi everyone, i'm trying to add buttons in certain columns of my p-table,

actually i'm doing that in my html :


Code: Select all

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

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 16 guests