从材料表中的FilterPredicate在Angular App中不起作用



我想为材料表实现客户过滤器,但是当我调试并在此客户过滤器功能中设置断点时。但这是不起作用的。

代码就是这样:


ngOnInit() {
    if (
      !this.displayedColumns &&
      this.tableData.rows.length > 0 &&
      !this.isFilterAvailable
    ) {
      this.displayedColumns = _.keys(_.first(this.tableData.rows));
    } else {
      this.dataSource.data = this.tableData.rows;
      this.initFilterValues(_.keys(_.first(this.tableData.rows)));
      this.dataSource.filterPredicate = this.createFilter();
    }
    this.dataSource.data = this.tableData.rows;
    this.dataSource.filterPredicate = (data, filter) => {
      console.log(data + "hier hier hier");
      return true;
    };
  }
  initFilterValues(values) {
    values.forEach(key => {
      this.filters[key] = "";
    });
  }
  doFilter(filterValue: string, column: string) {
    this.filters[column] = filterValue.trim().toLocaleLowerCase();
    this.dataSource.filter = JSON.stringify(this.filters);
    this.dataSource.filterPredicate = (data, filter) => {
      console.log(data + "asdfasdfa");
      return true;
    };
  }
  createFilter() {
    console.log("create asdfasdfasdfasdfasdf");
    const filterFunction = function(data, filter): boolean {
      console.log("Function excuted" + data);
      let searchTerms = JSON.parse(filter);
      return true;
    };
    return filterFunction;
  }
}

在html中有一个输入字段,如果我提示搜索搜索,则将运行Dofilter,但是FilterFunktion将仅显示所有数据

的拳头行

最好的问候

leo

[已解决]我看到了同样的问题。设置了过滤器谓词,但永远不会被调用。我也重写了过滤器谓词。[编辑]我通过在应用过滤器之前设置谓词来解决此问题。

最新更新