I have a filter function that works well when I use a static column name like this:
this.listOfData = this.listOfData.filter((item: DataItem) =>
item.name.toLowerCase().indexOf(newValue.toLowerCase()) !== -1
);
Note: item.name
However, I need to search in every column of the item
, how can I accomplish that?
Note: name
needs to be dynamic.
The columns in my ListofData
are as follows:
listOfData({
id:
ticket_number:
status_name:
name: // the current function only targets this value.
created_by_full_name:
receive_time:
response_time:
resolution_time:
})
Update
Following Allabakash
's answer, I have the final code below, but it is generating various typescript errors:
ngOnInit(): void {
// This listens to the input value from the service and takes action on change.
this.globalSearchService.searchTerm.subscribe((newValue: string) => {
// Here is where you would apply your current filtering logic.
this.searchTerm = newValue;
if(newValue != null) {
this.visible = false
this.listOfData = this.listOfData.filter((item: DataItem) =>
let keys = Object.keys(item);
for (let key of keys) {
if (typeof item[key] === 'string' &&
item[key].toLowerCase().indexOf(newValue.toLowerCase()) !== -1) {
return true;
}
}
return false;
);
}
});
}