[英]Filtering per column with button angular material table
I want to have a filter button on the column headers whereby I can filter the results by clicking a checkbox, as well as multiple column filtering.我想在列标题上有一个过滤器按钮,我可以通过单击复选框来过滤结果,以及多列过滤。
This is what I've tried, the button loads the menu, but when clicked also starts the sorting, and the positioning isn't right:这是我试过的,按钮加载菜单,但点击时也开始排序,定位不正确:
<table mat-table [dataSource]="source" matSort (contextmenu)="onContextMenu($event)"
matRipple [matRippleRadius]="'15'"
[matRippleColor]="'#03a9f4'">
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name <button mat-button matSuffix mat-icon-button aria-label="Clear" [matMenuTriggerFor]="menu">
<mat-icon>filter_list</mat-icon>
</button>
<mat-menu #menu>
<ng-template matMenuContent>
<div *ngFor="let item of items">
<mat-checkbox class="mat-menu-item">{{item.name}}</mat-checkbox>
</div>
</ng-template>
</mat-menu>
</th>
<td mat-cell *matCellDef="let row"> {{row.name}} </td>
</ng-container>
<!-- Email Column -->
<ng-container matColumnDef="emailAddress">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Email Address </th>
<td mat-cell *matCellDef="let row"> {{row.emailAddress}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: columns;"></tr>
</table>
<mat-paginator [length]="source.length" [pageSizeOptions]="[10, 20, 50, 100]" showFirstLastButtons></mat-paginator>
Here is an example of what I want:这是我想要的一个例子:
Have you tried adding a click event to your filter button to prevent sorting?您是否尝试向过滤器按钮添加点击事件以防止排序?
(click)="foo($event)"
foo($event: Event) {
$event.stopPropagation();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.