Create A Search Bar Filter through Object

Hi All

So I have an API end Point that provided me with the following result set. Please see image of how it looks in the front-end.

I also Used <ion-segment></ion-segment> to filter but Name, City, Occupation.


I want to filter the same result by using the different criteria, which means,

  • On the Creatives Segment I want to type a person name and only filter using Full_name

  • On the City Segment I want to type a city name and only filter using the city from the object result

  • And So On …

My Code

Most of the code comes from Ionic V3 I just combined a lot of it


export class SearchPage {

    items: Array<string>;
    criteria: string = "creative";
    allPeople    : any;

    constructor(public navCtrl: NavController, public navParams: NavParams, private searchServ : SearchService,) {

    allCreativeUsers() {

            resp => {
                console.log( typeof (resp));
                this.allPeople = resp;


    ionViewDidLoad() {
        //console.log('ionViewDidLoad SearchPage');

    filterItems(ev: any) {
    // This code is from the Example

        let val =;

        if (val && val.trim() !== '') {
            // Get the matching person name from when I type in the search box


<ion-segment [(ngModel)]="criteria">
        <ion-segment-button value="creative"> Creatives </ion-segment-button>

        <ion-segment-button value="cities"> Cities </ion-segment-button>

    <div [ngSwitch]="criteria">

        <ion-list *ngSwitchCase="'creative'">
            <ion-searchbar  placeholder="Filter by names" showCancelButton color="danger" (ionInput)="filterItems($event)"></ion-searchbar>

            <ion-item *ngFor="let person of allPeople; let i = index;" (click)="viewProfile( person.user_id )">
                <ion-avatar item-start>
                    <img src="assets/imgs/avatar-ts-woody.png">

                <h2>{{ person.full_name}}</h2>

                <p>{{ person.occupation }}</p>

                <ion-note item-end>13-02-2019</ion-note>


        <ion-list *ngSwitchCase="'cities'">
            <ion-searchbar  placeholder="Filter by City" showCancelButton color="danger" (ionInput)="filterItems($event)"></ion-searchbar>




How Can I achieve this? Please help

Kind Regards

You want to create three additional object arrays. When the data is fetched, set the object arrays equal to the results you will want to use the newly created arrays for the population of your ion-list. I would use a switch statement within your filter function to determine how to filter. Clear the newly created object, populate it agin and then use Filter and forEach to populate the filtered items.