Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 来自物料表的filterPredicate未在应用程序中工作_Angular_Angular Material_Angular Material Table - Fatal编程技术网

Angular 来自物料表的filterPredicate未在应用程序中工作

Angular 来自物料表的filterPredicate未在应用程序中工作,angular,angular-material,angular-material-table,Angular,Angular Material,Angular Material Table,我想为我的物料表实现一个客户过滤器,但是当我调试并在这个客户过滤器函数中设置一个断点时。但它不起作用 代码如下所示: ngOnInit() { if ( !this.displayedColumns && this.tableData.rows.length > 0 && !this.isFilterAvailable ) { this.displayedColumns = _.keys(_.

我想为我的物料表实现一个客户过滤器,但是当我调试并在这个客户过滤器函数中设置一个断点时。但它不起作用

代码如下所示:


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将运行,但FilterFunction将只显示所有数据中的第一行数据

致以最良好的祝愿


Leo

我如何重现一个问题?为什么要重写谓词?请参阅此处的帮助,了解如何重现问题?为什么要重新编写谓词?请看这里的帮助