I enter a string in the filter and filter by name in the table. The code is working!

<input type="text" name="searchString" [(ngModel)]="searchString" /> <table> <tr *ngFor="let client of clients | filter: searchString"> <td>{{client.id}}</td> <td>{{client.name}}</td> <td>{{client.surname}}</td> <td>{{client.city}}</td> <td>{{client.street}}</td> <td>{{client.housenumber}}</td> <td>{{client.apartment}}</td> <td ><ul *ngFor='let phone of client.phones'>{{phone.phoneNumber}}</ul><br /></td> <td><button type="button" (click)="loadTask(client.id)">View Task</button></td> </tr> 

The code in pipe is:

 export class FilterPipe implements PipeTransform { transform(clients: any[], searchString: any): any { console.log('searchString', searchString); return searchString ? clients.filter(client => client.name.toLowerCase().indexOf(searchString) !== -1) : clients; }; } 

How to change pipe to filter by two columns? For example, by name and surname

  • And who wrote the code for FilterPipe ? - Stepan Kasyanenko
  • @Stepan Kasyanenko I'm on the example of tutorials - Anton Evseev
  • one
    if you need to filter by two fields - filter by two, you can call the filter twice, you can check in one function that the condition is fulfilled either for one field or for another - Grundy

1 answer 1

Having added (client.name + client.city) solved my problem