1

I have a Table Filter in Angular Material :-

enter image description here

I want an icon at the right side of this filter, like below :-

enter image description here

I have tried with many configurations, without luck.

<mat-form-field>
    <input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
    <span class="input-group-append">
      <button class="btn" (click)="doSomething()">
          <i class="fa fa-plus fa-fw"></i>
      </button>
    </span>
</mat-form-field>

Is there any simple way to achieve this?

5
  • 1
    What part of this are you struggling with exactly? is this what you are trying to do - stackblitz.com/edit/angular-kgbf9o ? Commented May 18, 2018 at 13:25
  • @Und3rTow, Thanks. I need exactly the same. Can we do it without writing css? Commented May 18, 2018 at 13:41
  • 1
    yes, you can handle the layout using angular-flex-layout, then you won't need to use CSS Commented May 18, 2018 at 13:43
  • 1
    Thanks again. I will go through this. Commented May 18, 2018 at 13:44
  • Working like a charm :) Commented May 18, 2018 at 17:52

1 Answer 1

2

Material 2 supports that in their documentation

<mat-form-field class="example-form-field">
  <input matInput type="text" placeholder="Clearable input" [(ngModel)]="value"/>
  <button mat-button *ngIf="value" matSuffix mat-icon-button aria-label="Clear" (click)="value=''">
    <mat-icon>close</mat-icon>
  </button>
</mat-form-field>

https://material.angular.io/components/input/examples

https://stackblitz.com/angular/eyrxeklkoyq?file=app%2Finput-clearable-example.ts

Sign up to request clarification or add additional context in comments.

1 Comment

This is adding a button inside the field itself. But, there is not any space between "Filter Line" and "Icon", as I have indicated in the image (what I want). @Und3rTow solution is working as per my requirement. >> Still it might be a good solution, if I do not want space. As it doesn't require flex.

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.