如何解决材料表 - 以编程方式触发过滤器
遵循这个sample,我知道我可以编写自己的this.dataSource.filterPredicate
。只要我搜索字符串,这就可以正常工作。我想根据使用过的 state
(=myFilterState
) 额外过滤。
我尝试使用像这样的谓词
this.dataSource.filterPredicate =
(data: MyElement,filter: string) => data.myType.useState === this.myFilterState;
我面临的问题是,当我更改 this.myFilterState
时,过滤器不会重新评估,直到我更改 filter
的字符串。只要 filter
保持为空,就不会触发 filterPredicate
。
有没有办法手动触发它 - 尽管 filter
的值?
解决方法
在对问题进行调查后,我发现只有当 filterpredicate
具有值时,源代码才会触发 filter
。否则不会触发。
因此我想出了用
覆盖内部_filterData
的解决方案
this.dataSource._filterData = (data: PropertyCompact[]) => {
this.dataSource.filteredData = data.filter(obj => this.dataSource.filterPredicate(obj,this.dataSource.filter));
return this.dataSource.filteredData;
};
如果发生变化,需要触发更新
this.dataSource._updateChangeSubscription();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。