Solvedcomponents [Table] - Add example with multiple filtering columns
βοΈAccepted Answer
@erickyi2006 I am using mat-menu, mat-select, mat-input
everywhere to meet my requirements for the mat-table
like context menu, column filter etc;
Other Answers:
@astra1 here is some snippet from my code:
<!-- repeat this to all columns -->
<ng-container cdkColumnDef="Column1">
<mat-header-cell *cdkHeaderCellDef>
<!-- instead of adding mat-sort-header directive to the mat-header-cell, i've move it on span tag to separate sorting and filtering icon .-->
<span mat-sort-header>Column1 </span>
<!-- i've applied css rules to the icon-->
<span (click)="onFilterClick('col1')" class="filter-icon">
<mat-icon>keyboard_arrow_down</mat-icon>
</span>
<filter-template [openFilter]="true" *ngIf="templateFor === 'col1' "></filter-template>
</mat-header-cell>
<mat-cell *cdkCellDef="let row">{{row.Column1}}</mat-cell>
</ng-container>
// mat-table component.ts
onFilterClick(templateFor:string){
this.templateFor = templateFor;
}
// inside the filter-template component.ts
@ViewChild('filterMenu') triggerMenu: MatMenuTrigger;
@Input() openFilter: boolean;
ngOnChanges(){
if(this.openFilter) {
this.triggerMenu.openMenu()
}
}
<!-- filter-template component.html -->
<span #filterMenu="matMenuTrigger" [matMenuTriggerFor]="menu" id="filter-panel">
<mat-menu #menu="matMenu" [overlapTrigger]="false">
<div (click)="$event.stopPropagation()" (keyup)="$event.stopPropagation()" (keydown)="$event.stopPropagation()">
<form autocomplete="off" (ngSubmit)="onFilterSubmit()" [formGroup]="filterForm">
<mat-form-field style="width: auto;">
<mat-select formControlName="op" placeholder="Condition:">
<mat-option *ngFor="let con of conditions" [value]="condi.id">
{{con.text}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field *ngIf="!forFirstValue">
<input formControlName="val1" matInput placeholder="Value">
</mat-form-field>
<mat-form-field class="font-sm" *ngIf="forSecondValue">
<input formControlName="val2" matInput placeholder="Second Value">
</mat-form-field>
<button [disabled]="hasNoValue" matRipple type="submit"></button>
</form>
</div>
</mat-menu>
</span>
I hope you'll get some clue from this snippet.
I have answered about this topic and create a repo explain how I did it Filtering different columns in a material table
This shows two separate text filters, but the concept would be the same for selects, checkboxes, etc.
https://plnkr.co/edit/oQOYQgW0vCx8tfAgb1w9?p=preview
EDIT: and here's a version filtering with a slider
Hi,
actually the mat(cdk)-table doesn't seem to be as flexible as promised.
I want to have a second header-row above the normal header-row
where i can have text-input fields for filtering each column
This doesn't seem to be possible as of right now ?
Regards,
Nick
Bug, feature request, or proposal:
Proposal.
What is the expected behavior?
It would be good to see an example showing multiple filters (in this case inputs/selects) to filter rows/cells in md-table.
You can see this as an example.
What is the current behavior?
Currently the filter example just shows how to filter multiple columns by a single input.