Reputation: 37
i need help with the filter in a datatable in angular project. The filter is working fine and is filtering the results in the table, but one I delete all the letters in the filter field, it returns an empty datatable, and again if I input only 1 letter it fill the table with the results.
Here is my html:
<mat-form-field>
<mat-label>Search</mat-label>
<input
matInput
(keyup)="applyFilter($event)"
placeholder="Search"
#input
/>
</mat-form-field>
My typescript file:
applyFilter(event: Event) {
let filterValue = (event.target as HTMLInputElement).value;
this.filterValue = filterValue;
console.log(filterValue);
this.dataSource.searchResults(this.filterValue);
}
And my datasource:
searchResults(name: string) {
this.appService.searchPatient(name).subscribe((data: any) => {
if (data) {
this.totalPatientsCountSubject.next(data);
this.patientsSubject.next(data);
console.log(data);
}
});
}
my service.ts:
public searchPatient(name: string) {
return this._httpClient
.get(`http://api.dentist.techup.me/patient/search/by/name?name=${name}`)
.pipe(
map((data: any) => {
return data.result;
}),
catchError(this._handleError)
);
}
Any help would be appreciated! Thanks in advance!
Upvotes: 0
Views: 720
Reputation:
Okay, looking at the name of the service method /search/by/name I am almost a 100% sure that this is not thought to be a filter in sense of "reduce the list to the matching entries" but it is a search method like "hand me all entries you can find that match ...".
To sum it up: It seems to be perfectly okay that you get an empty list when you enter nothing. This method returns only matches for the entered string. It won't return anything when there is no string to search with.
Maybe you have access to some documentation about the API. There must be another method to gather an entire, unfiltered list of all entries.
Upvotes: 1