Having an issue with a custom filter that is causing an error "
ERROR TypeError: Cannot read property 'filter' of undefined
". I need help fixing this as it's preventing anything from rendering on the page. Any suggestions on what changes I should make to correct this? Your assistance is greatly appreciated.
File: table-filter.pipe.ts
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: "tableFilter"
})
export class TableFilterPipe implements PipeTransform {
transform(list: any[], filters: any) {
//console.log("table-filter", list);
const keys = Object.keys(filters).filter(key => filters[key]);
const filterUser = (user: { [x: string]: any }) =>
keys.every(key => {
if (key == "sdob") {
return (
new Date(user["dob"]) >=
new Date(new Date(filters[key]).setHours(0, 0, 0, 0))
);
} else if (key == "edob") {
return (
new Date(new Date(filters[key]).setHours(0, 0, 0, 0)) >=
new Date(user["dob"])
);
} else if (
key === "dl" &&
user["assigned_to"].filter((e: { dl: any }) => e.dl === filters[key])
.length
) {
return user;
} else if (key === "score") {
const low = filters[key] === "20" && user["score"] <= filters[key];
const medium =
filters[key] === "50" && user["score"] < 50 && user["score"] >= 21;
const high =
filters[key] === "70" && user["score"] < 70 && user["score"] >= 51;
const veryHigh = filters[key] === "71" && user["score"] >= 71;
if (low || medium || high || veryHigh) {
return user[key];
}
} else {
return user[key] === filters[key];
}
});
if(list) {
let filterList = list.filter(filterUser);
list.sort((lhs, rhs) =>this.lowestScore(lhs.assigned_to) - this.lowestScore(rhs.assigned_to));
}
return keys.length ? list.filter(filterUser) : list;
}
lowestScore(assign: any) {
let filterData = assign.filter(item => Number(item.co_score));
let leastScrore = Math.min(...filterData.map(item => item.co_score));
return leastScrore;
}
}