I am using the clarity datagrid and I want to be able to filter based on a search filter the entire grid content.
I tried to create a pipe. The pipe is included inside the app.module. The pipe is called the first time the component is loaded (and nothing is supposed to happen), but for some reason, when I put something into my , nothing is happening. No call to the 'userFilter' pipe.
user.component.html
<input type="text" id="search" placeholder="Search..." ([ngModel])="searchTerm">
...
<clr-dg-row *clrDgItems="let user of users | userFilter: searchTerm" [clrDgItem]="user" (click)="backupSelectedUser(user)">
<clr-dg-cell>{{ user.username }}</clr-dg-cell>
<clr-dg-cell>{{ user.name }}</clr-dg-cell>
<clr-dg-cell>{{ user.firstName }}</clr-dg-cell>
</clr-dg-row>
...
search.pipe.ts
transform(items: any, term: any): any {
if (term === undefined) {
return items;
}
return items.filter(function (item) {
for (const property in item) {
if (item[property] === null) {
continue;
}
if (item[property].toString().toLowerCase().includes(term.toLowerCase())) {
return true;
}
}
return false;
});
}
UPDATE: I did a little typo for the ngModel. It should be [(ngModel)] instead!