1

I have an Angular material data table which is implemented in the way that described in Angular Material documentation:

https://material.angular.io/components/table/overview#filtering

My issue is with my data source, I have this data model:

export interface CustomerHistory {
  entity_id: number;
  email: string;
  name: string;
  lastname: string;
  cpfcnpj: string;
  cpfcnpj2: string;
  rg: string;
  phone1: string;
  phone2: string;
  country: string;
  state: string;
  city: string;
  address: string;
  FullAddress: string;
  cep: string;
  orders: CustomerOrders[];
}

The last Property is Order Array which is causing filter not working properly in the way that works with other fields

This is my Filter Function:

applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
}

My question is how can I search in Array Object property in my data source?

Adnan
  • 814
  • 12
  • 38
  • Possible duplicate of [Filtering specific column in Angular Material Table with filtering in angular?](https://stackoverflow.com/questions/49939979/filtering-specific-column-in-angular-material-table-with-filtering-in-angular) – bugs Jan 28 '19 at 16:13

1 Answers1

3

First, when you drawTable make sure to create a loop like

    this.dataSource.data.orders.forEach(element => {
    element.toString();
//turn CustomerOrders[] to string
});

After that, applyFilter() should work

`applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}`