【问题标题】:Filter based on multiple drop down selection in mat-table基于mat-table中的多个下拉选择进行过滤
【发布时间】:2019-01-25 16:13:56
【问题描述】:

根据这篇文章:How can I filter results based on multiple selections from dropdown?

,如果两个选定的值来自不相邻的列怎么办?

例如,如果两个下拉菜单是“名称”和“符号”?

dataSource.filter 是否将通配符作为输入?像 'Hydrogen*H'

如果没有,我们如何实现这个函数,以便它可以执行 AND 运算符?

【问题讨论】:

  • 在你的问题上加一些代码,让连击者理解你的问题。

标签: angular typescript mat-table


【解决方案1】:

只需使用类似的函数

  customFiltered() {
    return (data, filter) => {
      if (this.name && this.symbol)
        return data.name == this.name && data.symbol == this.symbol
      if (this.name)
        return data.name == this.name
      if (this.symbol)
        return data.symbol == this.symbol
      return true
    }
  }

那么你只需要

this.dataSource.filterPredicate =this.customFiltered();

你的变量 this.name 和 this.symbol 是你选择的 [(ngModel)]

你可以在stackblitz看到

【讨论】:

    猜你喜欢
    • 2019-12-26
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多