0

Detail

I am trying to implement search pipe through which user can search with email/ firstname/ lastname but right now it iss perfectly fine with email single search item. I want to search same text enter in input with email first name and last name.

Image

enter image description here

Search Pipe

import {Pipe} from '@angular/core';


@Pipe({
    name: "search"
})

export class SearchPipe {

    transform(value, term) {
        console.log(term + ' ' + value);
        if (term == null) {
            return null;
        }
        return value.filter((item) => item.Email.includes(term));
    }
}

Response

{
    "Id":1,
    "ApimId":"1",
    "FirstName":"Super",
    "LastName":"Admin","
    "Email":"ahmed@gmail.com"   
}
Malik Kashmiri
  • 5,741
  • 11
  • 44
  • 80

1 Answers1

2

You have done the hardest part, just change your pipe to filter based on email or first name or last name

import {Pipe} from '@angular/core';


@Pipe({
    name: "search"
})

export class SearchPipe {

    transform(value, term) {
        console.log(term + ' ' + value);
        if (term == null) {
            return null;
        }
        return value.filter((item) => {
            return item.Email.includes(term) || item.FirstName.includes(term) || item.LastName.includes(term);
        });
    }
}
Fabio Antunes
  • 22,251
  • 15
  • 81
  • 96
  • It solves my problem just one thing more, search is case sensative how I can resolve this? – Malik Kashmiri Sep 28 '16 at 05:57
  • @MalikKashmiri a simple way would be to uppercase your strings, but check this answer http://stackoverflow.com/questions/2140627/javascript-case-insensitive-string-comparison – Fabio Antunes Sep 28 '16 at 09:47