HTML this is the code of my component.html file in which i am adding filters on a table:
<mat-form-field>
<input matInput class="form-field" [formControl]="employeeFilter" >
<mat-placeholder>Employee Name </mat-placeholder>
</mat-form-field>
<mat-form-field>
<input matInput class="form-field" [formControl]="projectFilter" >
<mat-placeholder>Project Name</mat-placeholder>
</mat-form-field>
TS File: this is my ts file in which i have written code for filtering columns using this link code. ngOnInit(): void {
this.userdataService.getReports().subscribe(data=>{
this.userData=data;
this.dataSource = new MatTableDataSource(this.userData.response);
this.employeeFilter.valueChanges.subscribe((employeeFilterValue)=> {
this.filteredValues['employee'] = employeeFilterValue;
this.dataSource.filter = JSON.stringify(this.filteredValues);
});
this.projectFilter.valueChanges.subscribe((projectFilterValue) => {
this.filteredValues['project'] = projectFilterValue;
this.dataSource.filter = JSON.stringify(this.filteredValues);
});
this.dataSource.filterPredicate = this.customFilterPredicate();
this.dataSource.paginator = this.paginator;
});
}
this is the filter function.
customFilterPredicate() {
const myFilterPredicate = function(data:userData, filter:string) :boolean {
let searchString = JSON.parse(filter);
let employeeFound = data.employee.toString().trim().toLowerCase().indexOf(searchString.employee.toLowerCase()) !== -1
let projectFound = data.project.toString().trim().indexOf(searchString.project) !== -1
if (searchString.topFilter) {
return employeeFound || projectFound
} else {
return employeeFound && projectFound
}
}
return myFilterPredicate;
}
i am getting error in filter function while passing arguments in the following line
const myFilterPredicate = function(data:userData, filter:string) :boolean