Issue
How can i add a search functionality into a angular and ionic project. I tried doing this with the following code below but it doesn't work.
This is the code i tried
filterusers(evt)
{
const search = evt.srcElement.value;
console.log(search);
if(!search)
{
return;
}
this.employees = this.employees.filter(currentgoal =>
{
if(currentgoal.FName && search)
{
if(currentgoal.FName.toLowerCase().indexof(search.toLowerCase()) > -1)
{
return true;
}
return false;
}
});
}
how can I do it?
Solution
try below way
empData : any = [];
filterusers(evt)
{
const search = evt.srcElement.value;
if(!search)
{
return;
}
this.empData = this.employees;
let filtered = this.empData.filter((x) =>
x.FName.toLocaleLowerCase().replace(/ /g, "").includes(search.toLocaleLowerCase().replace(/ /g, "")));
this.employees= filtered;
if (!filtered.length) {
//no record found
}
}
also you can use search npm like ng2-search-filter
Answered By - Bansi29
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.