admin管理员组文章数量:1332395
<ng-container matColumnDef="jan">
<mat-header-cell [hidden]="true" *matHeaderCellDef style="font-size: 65%" class="white-text" fxHide [fxShow.gt-md]="true">
Jan
</mat-header-cell>
<mat-cell *matCellDef="let element" style="font-size: 65%"> <span> </span> </mat-cell>
I am trying to hide a column in angular 4 . I tried to use *ngIf
, but it says we are not allowed to use more than one ponent with *
sign. Even [hidden]
does not work.
<ng-container matColumnDef="jan">
<mat-header-cell [hidden]="true" *matHeaderCellDef style="font-size: 65%" class="white-text" fxHide [fxShow.gt-md]="true">
Jan
</mat-header-cell>
<mat-cell *matCellDef="let element" style="font-size: 65%"> <span> </span> </mat-cell>
I am trying to hide a column in angular 4 . I tried to use *ngIf
, but it says we are not allowed to use more than one ponent with *
sign. Even [hidden]
does not work.
2 Answers
Reset to default 3In your mat-header-row
, you define the columnsToDisplay
. You can use this field, to control which columns are shown:
ponent
columnsToDisplay = ['userName', 'age'];
template
<tr mat-header-row *matHeaderRowDef="columnsToDisplay"></tr>
For more details, see the docs.
This means that by changing your column list provided to the rows, you can easily re-order and include/exclude columns dynamically.
If you want to use [hidden]
property for hiding HTML element when using Angular Material, its better to begin the tag with classic HTML tag.
In your case, use <th></th>
instead of directly use <mat-header-cell></mat-header-cell>
.
<ng-container matColumnDef="jan">
<th
mat-header-cell
[hidden]="true"
*matHeaderCellDef
style="font-size: 65%"
class="white-text"
fxHide
[fxShow.gt-md]="true"
>
Jan
</th>
<mat-cell *matCellDef="let element" style="font-size: 65%">
<span> </span>
</mat-cell>
</ng-container>
Working example is available on Stackblitz.
本文标签: javascriptHiding a mat data table column in angular 4Stack Overflow
版权声明:本文标题:javascript - Hiding a mat data table column in angular 4 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742283683a2446555.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论