javascript - Hiding a mat data table column in angular 4 - Stack Overflow

<ng-container matColumnDef="jan"><mat-header-cell [hidden]="true" *matHead

<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.

Share Improve this question edited Mar 4, 2019 at 14:53 Kim Kern 60.6k20 gold badges217 silver badges214 bronze badges asked Mar 4, 2019 at 14:49 ThejasThejas 48910 silver badges30 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

In 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742283684a4414949.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信