I am trying to use a filter in javascript to search on an array. Following is my array:-
"customerStatusInfoList": [
{
"customerId": 1110000012,
"caseStatus": "pending",
"customerName": "Robert",
"dateOfRequest": "2018-12-15 00:00:00.0"
},
{
"customerId": 1110000004,
"auditorName": "DcbAdmin",
"caseStatus": "pending",
"customerName": "Sam",
"dateOfRequest": "2018-12-14 12:40:04.0"
}
]
And I am using the following function to filter the array:-
filterTable = event => {
console.log("event.target.value", event.target.value);
console.log("rows", this.state.rows);
if (event.target.value !== "") {
let newRow = this.state.rows.filter(items => {
console.log("item.name", items.customerName);
if (items.customerName!== null)
return items.customerName
.toLowerCase()
.includes(event.target.value.toLowerCase());
});
this.setState({ rows: newRow, query: event.target.value });
} else {
console.log("Query string is empty ", event.target.value);
let newRow = this.state.custList;
console.log("new row :", newRow);
this.setState({ query: event.target.value, rows: newRow });
}
};
I am able to filter on the customerName but when I try to filter using customerId or any other parameter I get customerId.includes is not a function. But it works on customerName. How can I filter on the entire table using JavaScript filter? Any help or suggestion is appreciated. Thank you.
items.customerNameyou are using customername here you can not filter the customerIdcustomerIdsince onlycustomerIdis a number. Could you a write a simple function to filter and point out what's not working?