1

I'm trying to achieve like this EXAMPLE in reusable table. But seems it is not working.

my stackblitz

data-table.ts

export class DropdownOption {
  filterOption : [];
}

  @Input() control: FormControl;
  @Input() options: DropdownOption[];
  @Output() selectionChange = new EventEmitter<MatSelectChange>();

  onSelectionChange(event) {
    this.selectionChange.next(event);
  }

target.component

<h3>table 1</h3>
  <app-data-table [tableData]="tableData1" [columnHeader]="columnHeader1" (selectionChange)="onSelectionChange($event)"></app-data-table>

  <h3>table 2</h3>
  <app-data-table [tableData]="tableData2" [columnHeader]="columnHeader2"> </app-data-table>
</div>

Problem is:

  1. i've add selectOption for 1st table only.. but its reflecting in my 2nd table also.

  2. is my model correct

    export class DropdownOption {
      filterOption : [];
    } 
    

    ?

jps
  • 20,041
  • 15
  • 75
  • 79
Mr. Learner
  • 978
  • 2
  • 18
  • 48
  • I dont see any select options passed into your table component – Vimal Patel Jul 27 '21 at 05:22
  • @VimalPatel thats where i got stuck :( .. and having some confusion in model also (interface) – Mr. Learner Jul 27 '21 at 05:22
  • For interface you only need @Input() options: filterOption : []; like this. – Vimal Patel Jul 27 '21 at 05:28
  • is it possible to create stackblitz pls? – Mr. Learner Jul 27 '21 at 05:30
  • What exactly are you looking for? – Vimal Patel Jul 27 '21 at 05:44
  • @VimalPatel am looking for reusable mat-table component with search and dropdown filter..!! .. like my mat-table should be generic and i should reuse that in any number of different components..thats what im trying to create in my stackblitz.. but endup with some understanding issue – Mr. Learner Jul 27 '21 at 05:47
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/235321/discussion-between-vimal-patel-and-mr-learner). – Vimal Patel Jul 27 '21 at 05:48
  • see that first you need know how to add multiple filters in angular mat table, you has an example in this SO: https://stackoverflow.com/questions/68495473/how-to-add-multiple-filters-in-angular-mat-table/68496521#68496521 – Eliseo Jul 27 '21 at 12:00

1 Answers1

0

After know how create a custom filter based in two conditions like this SO, I can imagine an options like

options={column:'status',options:['Any status','Active','Disabled']}

you only need create a FormGroup with two fields, "the filter" and the "dropdown"

field:string:null;
options:any[];
form:FormGroup;
subscription:any;
@Input('options') set options(value){
   this.field=value.column
   this.options=value.options
   this.form=new FormGroup({
     filter:new FormControl();
     select:new FormControl(0);
   })
   if (this.subscription)
      this.subscription.unsubscribe();

   this.subscription=this.form.valueChanges(res=>{
        ..here call to filter..
   }) 
}

You use the variable "options" to create the select

Eliseo
  • 50,109
  • 4
  • 29
  • 67
  • Luckily just found your answer from [HERE](https://stackoverflow.com/questions/54359980/filter-based-on-multiple-drop-down-selection-in-mat-table) .... this is what am actually trying to convert as reusable component... can you pls help me on that – Mr. Learner Jul 27 '21 at 16:42