'Filter items from a drop-down list
In an HTML table, I have a dropdown list on the right, which is called type, there are two items (in and out).
My goal is to filter the items: If I select from my IN dropdown, I should see all the items in the HTML here is an example.
My problem is that when I choose an item from my list. For example IN, HTML table data does not filter. Unfortunately, I don't get any error message...
I tried to debug:
public selectedBrand: any;
public onChangeType(type:any) {
console.log("Begin ");
this.selectedBrand=type;
this.filteredCustomer=this.customerTransferts.filter(
(item) => item.type === this.selectedBrand
);
console.log("Data");
console.log(this.filteredCustomer);
}
I don't have any error
I have the impression that there is a problem in the HTML?
<select class="form-select" style="max-width: 100px" [ngModel]="selectedBrand" (ngModelChange)="onChangeType($event)">
<option [value]="'IN'">IN</option>
<option [value]="'OUT'">OUT</option>
</select>
Thank you for your help.
Solution 1:[1]
Make sure to have case insensitive filter if needed
Change the code like this and try again
this.filteredCustomer = this.customerTransferts.filter(
item => item.type.toLowerCase() === this.selectedBrand.toLowerCase()
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nice18 |
