0

.HTML:

How to implement the filter in this component as I have implemented it with the expansion table, but my filter is not working.

    <mat-dialog-content style="width: 63rem; overflow: initial;">       
      <div class="searchField">
        <mat-form-field appearance="standard">
          <mat-label>Filter</mat-label>
          <input matInput (keyup)="applyFilter($event)" placeholder="Ex. Tele" #input>
        </mat-form-field>
      </div>  
     
    </mat-dialog-content>

.TS:

    getProductList() {
        this.commonservice.getProdList().subscribe((response: any) => {
          console.log('Response from API is ', response);
          if (response) {
            this.productInfo = response;
            this.dataSource = this.productInfo;
            console.log('Product Info ', this.productInfo);
          }
        }, (error) => {
          console.log('Error is ', error);
        });
      }

    applyFilter(event: Event) {
        const filterValue = (event.target as HTMLInputElement).value;
        this.dataSource.filter = filterValue.trim().toLocaleLowerCase();
        console.log('filtered data ', this.dataSource.filter);
      }

I have implemented Filter and Going to filter "Saas" I have filtered "Saas" but it's unable to filter it.

1 Answer 1

1

Assuming dataSource is an array

this.dataSource = this.dataSource.filter((d)=>d === filterValue.trim().toLocaleLowerCase());
Sign up to request clarification or add additional context in comments.

3 Comments

Still, I am not able to filter the data.
Your datasource is an array of object. you need to do "d.somePropertyOfObjectInArray === filterValue.trim().toLocaleLowerCase()"
I was using this: this.dataSource = this.dataSource.filter((d:any) => d.product_name === filterValue.trim().toLocaleLowerCase());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.