I am trying to change the filter logic in angular datatable
export class FilterPipe implements PipeTransform {
keys = [];
transform(items: any, args: string): any {
console.log('Datatable test');
if (items != null && items.length > 0) {
let ans = [];
if (this.keys.length == 0) {
this.keys = Object.keys(items[0]);
}
for (let i of items) {
for (let k of this.keys) {
if (String(i[k]).toLowerCase().indexOf(args.toLowerCase()) >= 0) {
ans.push(i);
break;
}
}
}
return ans;
}
}
}
I kept a console.log and recompiled the application. The changes are not reflecting.
Someone please give some light on it ?
You are lacking an
else
statement that covers the fact that your items are empty or null/undefined.Also, you can simplify your full text search like this :