Angular 按钮点击条件下的过滤垫表

Angular 按钮点击条件下的过滤垫表,angular,angular-material,Angular,Angular Material,我有一个mat表,我想筛选它以显示表中权重大于10的行。关于如何做到这一点有什么建议吗 请在此处查看我的stackblitz: 我已经为您的用例添加了逻辑。请检查一下 filterTable() { // logic here to filter table showing only rows that have a weight > 10 this.dataSource = this.dataSource.filter((item) => { c

我有一个mat表,我想筛选它以显示表中权重大于10的行。关于如何做到这一点有什么建议吗

请在此处查看我的stackblitz:


我已经为您的用例添加了逻辑。请检查一下

filterTable() {
    // logic here to filter table showing only rows that have a weight > 10
    this.dataSource = this.dataSource.filter((item) => { 
         console.log(Math.floor(item.weight));
         return Math.floor(item.weight) > 10});
         console.log('***********', this.dataSource);
}
试试这个

filterTable() {
        // logic here to filter table showing only rows that have a weight > 10
        this.dataSource = ELEMENT_DATA.filter(df => df.weight > 10)
      }

你能分享你的stackblitz代码url吗?共享url是您代码的输出。已更新stackblitz!太棒了-这很有效!太棒了-这很有效!我在动态数据上使用它,并得到错误类型错误:无法读取未定义的属性“filter”。如何对此进行故障排除?