Could you update the block of code for me?
return filterKeys.some((keyName) => {
return new RegExp(filter[keyName], 'gi').test(item[keyName]) ||
new RegExp(filter[keyName], 'gi').test(item.data[keyName]) ||
filter[keyName] == "";
});
Here is the updated version:
return (
new RegExp(filter[keyName], "gi").test(item[keyName]) ||
new RegExp(filter[keyName], "gi").test(item.data[keyName]) ||
new RegExp(filter[keyName], "gi").test(item.data.data) ||
filter[keyName] == ""
);
I included an extra line to address nesting according to your data structure.
Additionally, I noticed a small mistake in your code while iterating through the keys for the search to be effective across all fields. Please replace the else block with this code:
let keys = [];
return items.filter(item => {
keys = Object.keys(item);
keys.push(...Object.keys(item.data));
return keys.some(keyName => {
console.log(keyName);
return (
new RegExp(filter, "gi").test(item[keyName]) ||
new RegExp(filter, "gi").test(item.data[keyName]) ||
new RegExp(filter, "gi").test(item.data.data) ||
filter[keyName] == ""
);
});
});