Фильтр Предикат из таблицы материалов не работал в угловом приложении - PullRequest
0 голосов
/ 17 мая 2019

Я хочу реализовать фильтр клиента для моей таблицы материалов, но по мере отладки и установки точки останова в этой функции фильтра клиента. но это не сработало.

код такой, как этот:


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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...