Bhrungarajni
Bhrungarajni

Reputation: 2535

How to filter the contents on search irrespective of case sensitive using angular2

i am able to search the contents based on the keyin. But the parent has its child components,so for Example: I am trying to filter the contents with "c", if i do so, i get the parent and 1 child, but here i have 2 child components one with "Check" and other with "check_test". When i try to filter with alphabet "c" i must get both the child copmonents irrespective of case sensitive.

TS:

searchFacility(search) {
    this.sLetter = search;
    if (search) {
      this.dtFacilities.expandedRows = [];
      setTimeout(() => {
        this.dtFacilities.expandedRows = this.dtFacilities.value;
        this.dtFacilities.value.forEach(m => {
          m.memberFacilities.forEach(f => {
            if (f.facilityName.includes(search)) {
              f.isShowMember = false;
            } else {
              f.isShowMember = true;
            }
          })
        })
      }, 100);
    }

    else {
      this.dtFacilities.expandedRows = [];
      this.dtFacilities.value.forEach(m => {
          m.memberFacilities.map(val => {
            val.isShowMember = false;
          })
        })
    }
  }

Here in this section,

if (f.facilityName.includes(search)) {
                  f.isShowMember = false;
                } else {
                  f.isShowMember = true;
                }
              })

for search, it is taking "c", so it is going for else condition there by making the "Check" isShowMember flag as true.

DEMO

Upvotes: 0

Views: 44

Answers (1)

Andrew
Andrew

Reputation: 5277

let mySearch = search.toLowerCase();
let facilityName = f.facilityName.toLowerCase();
if (facilityName && facilityName.includes(search)) {
                  f.isShowMember = false;
                } else {
                  f.isShowMember = true;
                }
              })

Upvotes: 1

Related Questions