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?

1

1 Answer 1

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();
}`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.