So, if the row.id has value(say: id_1313) I want to add a click event to mat-row else I need to simply display the mat-row.
I'll provide a sample code of what I actually did
app.component.html
<table
mat-table
[dataSource]="dataSource"
width="100%"
>
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef>
Date
</th>
<td mat-cell *matCellDef="let element">{{ element.date }}</td>
</ng-container>
<ng-container *matRowDef="let row; columns: displayedColumns">
<div
*ngIf="
row.id;
then hasId;
else notHasId
"
></div>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr
#hasId
mat-row
(click)="hasId()"
*matRowDef="let row; columns: displayedColumns"
></tr>
<tr
#notHasId
mat-row
*matRowDef="let row; columns: displayedColumns"
></tr>
</ng-container>
I know the approach I tried is not gonna work, any ideas to do changes only on mat-row. I don't want to use *ngIf for each column value in the ng -container
EDIT
I found the answer after some research. We can enable the click method using ternary operator. The demo code is below.
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr
mat-row
*matRowDef="let row; columns: displayedColumns"
(click)="row.id != null ? displayDetails(row) : null"
></tr>