Quiero filtrar mis datos usando Nombre, número de móvil por un campo de entrada como filtro de tabla de datos de material. constructor:
constructor() { this.filteredPatient = this.patientsearch.valueChanges .pipe( startWith(''), map(p => p ? this._filterPatient(p) : this.patients.slice()) ); } private _filterPatient(value: string): IPatient[] { const filterValue = value.toLowerCase(); const searchByfirstName = this.patients.filter(p => p.firstName.toLowerCase().includes(filterValue)); const searchBylastName = this.patients.filter(p => p.lastName.toLowerCase().includes(filterValue)); const searchBymobileNumber = this.patients.filter(p => p.mobileNumber.toLowerCase().includes(filterValue)); const mergedObj = { ...searchByfirstName, ...searchBymobileNumber }; return mergedObj; }Pero esto no está funcionando . ¿Alguien puede sugerirme cómo puedo filtrar datos?
Puedes lograrlo de la siguiente manera:
private _filterPatient(value: string): IPatient[] { const filterValue = value.toLowerCase(); const result = this.patients.filter( (p) => p.firstName?.toLowerCase().includes(filterValue) || p.lastName?.toLowerCase().includes(filterValue) || p.mobileNumber?.toLowerCase().includes(filterValue) ); return result; }