0
votes

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?

1

1 Answers

2
votes

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();
}`