angular - 如何将图标添加到 mat-table 中的 mat-sort-header
问题描述
我正在使用mat-table,我需要在 mat-sort-header 中添加一个自定义图标,但是现在如果我单击图标,表格将被排序,我不想要这种行为,这是代码:
<!-- line Column -->
<ng-container matColumnDef="line">
<th mat-header-cell *matHeaderCellDef mat-sort-header disableClear>
line
<span *ngIf="lineFiltered == false; else noFilteredline" (click)="filterLine.toggle($event)" class="filter">
<i class="fa fa-filter" aria-hidden="true"></i></span>
<ng-template #noFilteredline>
<span (click)="filterLine.toggle($event)" class="filter success"
><i class="fa fa-filter" aria-hidden="true"></i
></span>
</ng-template>
</th>
<td mat-cell *matCellDef="let row">{{ row.line }}</td>
</ng-container>
这是排序标题:
如果我把图标放在外面,它就不会出现。
ps 我不能使用 event.stopPropagation()
解决方案
这段代码解决了我的问题:
<!-- line Column -->
<ng-container matColumnDef="line">
<th mat-header-cell *matHeaderCellDef>
<div class="d-flex">
<span *ngIf="lineFiltered == false" (click)="filterLine.toggle($event)" class="filter"
><i class="fa fa-filter" aria-hidden="true"></i
></span>
<span mat-sort-header disableClear> {{ "contactlens.table.headers.line" | translate }}</span>
</div>
</th>
<td mat-cell *matCellDef="let row">
{{ row.line }}
</td>
</ng-container>
推荐阅读
- flutter - 单击按钮时调用一个类
- microsoft-graph-api - 获取 Outlook MIME 消息时不支持 OData 请求
- load-balancing - 如何在 HA 集群中托管来自 Jboss EAP 7.1 从属的静态内容?
- javascript - 选择标签在多行的动态表中不起作用
- java - Solr 更新问题
- ruby-on-rails - 安装 json (1.8.1) 时出错,Bundler 无法继续
- angularjs - 显示 div 取决于使用 ng-show、ng-click、ng-init 的点击次数
- javascript - 简单的 Rails 应用程序 - 未捕获的 ReferenceError:$ 未定义
- android - web3j 和 web3js 中的签名不同?
- java - CalendarView 在片段中不起作用?安卓