Filtering specific column in Angular Material Table with filtering in angular?

前端 未结 4 885
温柔的废话
温柔的废话 2021-02-19 00:44

I am using mat-table. It has a filter which works fine.

Filter happened against this below data (All columns)

const ELEMENT_DATA: Element[] = [
  {posit         


        
4条回答
  •  抹茶落季
    2021-02-19 01:33

    You have to override the filterPredicate of your dataSource.

    Here's an example of how to do it: Working demo


    Essentially, you want to specify what properties in your data the filter is applied to:

    this.dataSource.filterPredicate = function(data, filter: string): boolean {
        return data.name.toLowerCase().includes(filter) || data.symbol.toLowerCase().includes(filter) || data.position.toString().includes(filter);
    };
    

提交回复
热议问题