[Fixed] When filter is empty it returns empty array


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:


My typescript file:

applyFilter(event: Event) {
    let filterValue = (event.target as HTMLInputElement).value;
    this.filterValue = filterValue;

And my datasource:

searchResults(name: string) {
    this.appService.searchPatient(name).subscribe((data: any) => {
      if (data) {

my service.ts:

 public searchPatient(name: string) {
    return this._httpClient
        map((data: any) => {
          return data.result;

Any help would be appreciated!
Thanks in advance!


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.

Leave a Reply

(*) Required, Your email will not be published