-
Notifications
You must be signed in to change notification settings - Fork 6.8k

Description
Bug, feature request, or proposal:
Possibility to hide some columns directly in template
What is the expected behavior?
Actually, I have a datable like this:
<mat-table #table [dataSource]="dataSource">
<ng-container matColumnDef="col1">
<mat-header-cell *matHeaderCellDef>h1</mat-header-cell>
<mat-cell *matCellDef="let element">c1</mat-cell>
</ng-container>
<ng-container matColumnDef="col2">
<mat-header-cell *matHeaderCellDef>h2</mat-header-cell>
<mat-cell *matCellDef="let element">c2</mat-cell>
</ng-container>
</mat-table>
I would like to have something like this (by exemple):
<ng-container matColumnDef="col1" [matColumnDisplay]="expr">
<mat-header-cell *matHeaderCellDef>h1</mat-header-cell>
<mat-cell *matCellDef="let element">c1</mat-cell>
</ng-container>
matColumnDisplay is a boolean expression to know if this column must be displayed or not (===> removed from the DOM)
or why not:
<ng-container matColumnDef="col1" *ngIf="expr">
==> but it causes an error
By exemple:
[matColumnDisplay]="currentDisplay === 'mobile'"
or
[matColumnDisplay]="isColumnHidden === myVar"
What is the current behavior?
The only possible today is:
add css class to and
By exemple: <mat-header-cell class="d-none d-md-block">
==> Work but, the element is not remove from the DOM and lots of css class to add.
Play with matHeaderRowDef and matRowDef and have several variables:
const menuMobile = ['col1'];
const menuDesktop = ['col1', 'col2', ...];
const menuInTheCaseOf = ['col1', 'col3', ...];
==> Work but, add a lot of codes to manage several cases
What are the steps to reproduce?
What is the use-case or motivation for changing an existing behavior?
To have the simplest and shortest code to manage responsive case or fonctional case in columns display
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
5.2.x