【问题标题】:How to create custom filtering using MatTableDataSource in angular 5?如何在 Angular 5 中使用 MatTableDataSource 创建自定义过滤?
【发布时间】:2023-03-09 13:43:01
【问题描述】:

Angular 材料官网Angular Material Table 中提到 filterPredicate: ((data: T, filter: string) => boolean) 将根据特定字段过滤数据。但不知道如何开始。有没有这方面的例子。

【问题讨论】:

    标签: angular mat-table angular-material-table angular-material-5


    【解决方案1】:

    这个答案似乎显示了如何使用过滤谓词:

    https://stackoverflow.com/a/50174938/6130716

    它是这样工作的:

    this.dataSource.filterPredicate = (data: MyObject, filter: string) => {
      return data.property == filter;
    };
    
    this.dataSource.filter = myValue;
    

    【讨论】:

    • 感谢@peter 的回复,它工作正常。
    • 你会在 ngOnInit 中这样做吗?
    猜你喜欢
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    • 2016-11-26
    • 2020-04-28
    • 2019-03-16
    • 2021-09-03
    • 2018-10-24
    • 1970-01-01
    相关资源
    最近更新 更多