Reputation: 269
I have first name and last name in two different columns in my database, so I had to bind it this way to show it as 1 in my table.
However my search function isn't working when I type in space between first and last name:
<tbody>
<tr *ngFor="let e of employeelist | filter : searchByName">
<td>{{e.firstName}} {{e.lastName}}</td>
import { Injectable, Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter'
})
@Injectable()
export class FilterEmployeesPipe implements PipeTransform {
transform(value: any, input: string) {
if (input) {
input = input.toLowerCase();
//filter je filter() metod iz array.prototype.filter
return value.filter(function (employee: any) {
return ((employee.firstName.toLowerCase().indexOf(input)) &&
(employee.lastName.toLowerCase().indexOf(input))) > -1;
})
}
return value;
}
}
Upvotes: 1
Views: 416
Reputation: 657068
You need to include the space in the string that you use to match the input
return (employee.firstName.toLowerCase() + ' ' employee.lastName.toLowerCase()).indexOf(input) > -1;
otherwise you're comparing apples with pears.
Upvotes: 0
Reputation: 378
Use do like this
<td>{{e.firstName + ' ' +e.lastName}}</td>
Upvotes: 1