[英]with Angular how to stopPropagation() of checkbox click event inside a table row?
I have an angular material table with a row showing customers and another child table showing their orders.我有一个角度材料表,其中一行显示客户,另一个子表显示他们的订单。 On clicking anywhere in the row it expands the row for showing the customers orders.
单击行中的任意位置时,它会展开行以显示客户订单。 When I click in the checkbox in the customer row I don't want the orders child table to open.
当我单击客户行中的复选框时,我不希望打开订单子表。 I have tried a couple of things but with no luck.
我尝试了几件事,但没有运气。 Can someone recommend what would work with this scenario.
有人可以推荐什么适用于这种情况。 Your helps really appreciated, thanks!
非常感谢您的帮助,谢谢!
I have tried putting (click)="$event.stopPropagation();
on the checkbox, on the container as well and that didnt work. I also tried to make a directive as shown in In Angular, how to stopPropagation() of TR click event when checkbox has change event? but this still does not stop the (click)="expandCollapse(row)
on the <tr>
from firing.我试过把
(click)="$event.stopPropagation();
放在复选框上,放在容器上,但没有奏效。我还尝试制定一个指令,如在 Angular, how to stopPropagation() of TR 中所示复选框具有更改事件时的单击事件?但这仍然不会阻止<tr>
上的(click)="expandCollapse(row)
触发。
Checkbox code:复选框代码:
<ng-container *ngIf="column.key == 'all' && column.key !== 'sort'">
<th mat-header-cell *matHeaderCellDef [style.width.px]="75">
<mat-checkbox (click)="$event.stopPropagation();
(change)="$event ? masterToggle() : null"
[checked]="hasValue() && isAllSelected()"
[indeterminate]="hasValue() && !isAllSelected()"
>
</mat-checkbox>
<span class="checkbox-text"></span>
</th>
<td mat-cell *matCellDef="let row">
<mat-checkbox
(change)="$event ? toggle(row.customerId) : null"
[checked]="isSelected(row.customerId)">
</mat-checkbox>
</td>
</ng-container>
Parent material row:父材料行:
<tr mat-row
[ngClass]="{'highlighted': isSelected(row.customerId) }"
*matRowDef="let row; columns: columnKeys;" class="example-element-row"
[class.example-expanded-row]="isSelected(row.customerId)"
(click)="expandCollapse(row)" id="rowcustomer-{{row.rowIdex}}">
</tr>
If you followed the documentation sample of Angular Material ( Angular Material)如果您遵循 Angular Material ( Angular Material)的文档示例
by default you would have something like below in your component.html file:默认情况下,您的 component.html 文件中会有如下内容:
<tr mat-row *matRowDef="let row; columns: displayedColumns;"
(click)="selection.toggle(row)"
</tr>
you remove the click event so it would look like below:您删除点击事件,使其如下所示:
<tr mat-row *matRowDef="let row; columns: displayedColumns;"
</tr>
and it should work它应该工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.