我希望能够根据用户选择进行过滤。如果我在过滤器中硬编码它可以工作,但当我尝试使用' selectSeachColumn'作为过滤器中的变量,我收到错误消息:"无法读取属性' selectSeachColumn'未定义",是否我将变量硬编码如下或将其连接到选择。
这是我到目前为止所做的:
HTML(我使用自定义管道"键":
选择输入:
<md-select placeholder="Search in..." [(ngModel)]="selectSeachColumn">
<md-option *ngFor="let col of tableColumnNames | keys" [value]="col.key">
{{ col.value }}
</md-option>
</md-select>
表格:
<input
type='text'
style='padding:8px;margin:15px auto;width:30%;'
placeholder='Type to filter the name column...'
(keyup)='updateFilter($event)'
/>
<ngx-datatable
#table
class='material'
[columns]="columns"
[columnMode]="'force'"
[headerHeight]="50"
[footerHeight]="50"
[rowHeight]="'auto'"
[limit]="5"
[rows]='rows'>
</ngx-datatable>
TS:
selectSeachColumn = 'purchaseOrder';
updateFilter(event) {
const val = event.target.value;
this.temp = [...this.rows];
const temp = this.temp.filter(function(d) {
return d.selectSeachColumn.indexOf(val) !== -1 || !val;
});
// update the rows
this.rows = temp;
// Whenever the filter changes, always go back to the first page
this.table.offset = 0;
}