I need to filter the table data according to the value I set in the input on keyup
event. As there are multiple columns, filtered data should be displayed accordingly.
In my html I have below
<tr>
<td *ngFor="let t of tableHeader">
<input type="text" [id]="t.key" (keyup)="inputChange($event)">
</td>
</tr>
My TS file is as below
public inputChange(value) {
var prevData = this.dataSource;
if (this.selectedId == '') {
prevData = this.result;
}
else if (this.selectedId != '' && this.selectedId != value.target.id) {
prevData = this.result;
}
if (this.selectedId != '' && filterValue.target.value == '') {
this.result = prevData;
return;
}
this.selectedId = value.target.id;
this.inputValue = value.target.value;
var filteredData = this.result.filter(x => x[this.selectedId] && x[this.selectedId].toString().toLowerCase().includes(this.inputValue.toLowerCase()));
this.result = filteredData;
}
So far I have done this and get data filtered accordingly, but when I remove a value from a particular filter input, it loads the data source.
Expected: to display the previously filtered data instead of the data source.