angular - Apply datasource.filter to a *ngFor
问题描述
I have a mat-table that filters based on the search criteria that you give for which I used the example on: https://material.angular.io/components/table/examples
Is it possible to apply this filter to an *ngFor
? My ultimate goal is to update my markers according to the table filter.
This is the map I want to apply it to:
<agm-map [latitude]="lat" [longitude]="lng" (mapClick)="placeMarker($event)">
<agm-marker *ngFor="let marker of markers" [iconUrl]="marker.edit ? 'assets/selectedMarker.png' : ''" [latitude]="marker.lat" [longitude]="marker.lang">
<agm-info-window>{{marker.id}}</agm-info-window>
</agm-marker>
</agm-map>
And this is my table:
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
</mat-form-field>
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> Wagonnumber </th>
<td mat-cell *matCellDef="let element">{{element.id}}</td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="lat">
<th mat-header-cell *matHeaderCellDef> Plate </th>
<td mat-cell *matCellDef="let element"> {{element.lat}} </td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="lang">
<th mat-header-cell *matHeaderCellDef> Status </th>
<td mat-cell *matCellDef="let element"> {{element.lang}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
解决方案
我能够使用 datasource.filteredData 解决它。
所以:
this.markers = this.datasource.filteredData;
推荐阅读
- javascript - 如何从geojson为mapbox GL获取'line-dasharray'值
- haskell - 泛型:具有实例的类型的运行时 ADT
- json - 通过 json 数组映射来渲染屏幕 React Native
- python-3.x - 如何在使用 Flutter 的同时开发后端
- mysql - MySQL8.20中服务器请求客户端未知的身份验证方法
- python - 根据另一列值删除字符串中的单词
- azure-functions - 如何解决 Alexa 问题请求的技能响应?
- c++ - 在声明的同一行从 lambda 返回值
- reactjs - React ref.current 内部循环仅在第一次迭代时起作用
- python - 如何根据列唯一集将行保留在 DataFrame 中?