Primeng: Remove onRowClick from Table

Created on 1 Feb 2018  路  2Comments  路  Source: primefaces/primeng

It is redundant as it can easily be done with

enhancement

Most helpful comment

@wz2b You can bind click event on tr element in table.

<p-table [columns]="cols" [value]="cars">
    <ng-template pTemplate="header" let-columns>
        <tr>
            <th *ngFor="let col of columns">
                {{col.header}}
            </th>
        </tr>
    </ng-template>
    <ng-template pTemplate="body" let-rowData let-columns="columns">
        <tr (click)="onRowClick($event, rowData)">   <!-- like this -->
            <td *ngFor="let col of columns">
                    {{rowData[col.field]}}
            </td>
        </tr>
    </ng-template>
</p-table>

All 2 comments

It is NOT redundant. Row selection is NOT the same as generic "click" event. A row selection is supposed to send you back the model (the content of the row). Click sends you back a MouseEvent.

@wz2b You can bind click event on tr element in table.

<p-table [columns]="cols" [value]="cars">
    <ng-template pTemplate="header" let-columns>
        <tr>
            <th *ngFor="let col of columns">
                {{col.header}}
            </th>
        </tr>
    </ng-template>
    <ng-template pTemplate="body" let-rowData let-columns="columns">
        <tr (click)="onRowClick($event, rowData)">   <!-- like this -->
            <td *ngFor="let col of columns">
                    {{rowData[col.field]}}
            </td>
        </tr>
    </ng-template>
</p-table>
Was this page helpful?
0 / 5 - 0 ratings