I'm new to Angular.
I have a demo array like this:
for (let index = 1; index <= 100; index ) {
this.listOfData.push([
`Name ${index}`,
`Math.floor(Math.random() * 100)`,
'Employee',
]);
}
And I try to create a filter table with search function:
onSearch = (value) => {
const output = this.listOfData.filter((arr) =>
arr.some((item) => {
item.toLowerCase().includes(value);
})
);
console.log('output: ', output);
this.listOfDisplayData = output;
};
This is my demo
CodePudding user response:
So basically your data item is [[string,string,string],...]
when you start filtering with filter
you must return true
for it to include and false
to filter it out.
This should fix it
onSearch = (value) => {
const output = this.listOfData.filter((arr) =>
arr.some((item) => {
if (item.toLowerCase().includes(value)) {
return true;
} else {
return false;
}
})
);
console.log('output: ', output);
this.listOfDisplayData = output;
}