如何在动态数据中使用NGIF来显示元素到页脚。

问题描述 投票:0回答:1

我需要在我的行Datatable中显示页脚元素,只是如果我在一个特定的列中,我知道在一般情况下如何做,但在这里我使用编程行def(我应该使用它进行分组

所以我试过那个代码。

Template:

<mat-table [dataSource]="dataSource" class="mat-elevation-z8">

            <ng-container *ngFor="let column of columns; let i = index" matColumnDef="{{ column.field }}">
              <mat-header-cell *matHeaderCellDef (click)="SortWith($event,column)">{{ column.field }}


              </mat-header-cell>
            <mat-cell *matCellDef="let row">
                <div >
                    {{ row[column.field] }}
                </div>
            </mat-cell>
            <mat-footer-cell *matFooterCellDef *ngIf="column.field == Category"> <b><font color=red>Total: </font></b></mat-footer-cell> // I need to dispaly this just in column of category

        </ng-container>

              <mat-header-row mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
              <mat-row *matRowDef="let row; columns: displayedColumns;" [className]="row.RemainingQuantities == 0 ? 'red' : 'redBack'"></mat-row>
              <mat-row *matFooterRowDef="displayedColumns; sticky: true"></mat-row>

              <!-- Group header -->
              <ng-container matColumnDef="groupHeader">
                  <mat-cell colspan="999" *matCellDef="let group">
                <mat-icon *ngIf="group.expanded">expand_less</mat-icon>
                <mat-icon *ngIf="!group.expanded">expand_more</mat-icon>
                      <strong>{{groupByColumns[group.level-1]}} = {{group[groupByColumns[group.level-1]]}} ({{group.totalCounts}})</strong>
                </mat-cell>
            </ng-container>

My component. ts:

this.columns = [{
      field: 'Category'
    },  {
      field: 'Model'
    },  {
      field: 'Reference'
    },  {
      field: 'Name'
    },  {
      field: 'RemainingQuantities'
    },  {
      field: 'Department.Name'
    },  {
      field: 'Supplier.Name'
    }];
    this.displayedColumns = this.columns.map(column => column.field);
    this.groupByColumns = ['Category'];
 columnsToDisplay: string[] = ['Category', 'Model', 'Reference', 'Name', 'RemainingQuantities', 'Department.Name', 'Supplier.Name'];
   SortedColumns: string[] = [];
    this.service.get_product().subscribe((result : any)=>{
      this.listdata = result;

      this.decompersed = decrypt(result);
      console.log(this.decompersed);
      this.ProductList = this.decompersed;
      this.dataSource.data = this.addGroups(this.ProductList, this.groupByColumns);
      this.dataSource.filterPredicate = this.customFilterPredicate.bind(this);
      this.dataSource.filter = performance.now().toString();

但是我发现了一个错误:

未捕获错误: 模板解析错误。不能在一个元素上有多个模板绑定。只能使用一个以*为前缀的属性(" ]*ngIf="column.field == Category"> Total: ")。

当我删除NgIf时,我发现了这个结果。

enter image description here

只是我需要第一个总标签

angular typescript
1个回答
0
投票

解决方法是使用 [className]="column.field == 'Category' ? 'nothing' : 'hidetool'" 而hidetool类中包含了hide att。

© www.soinside.com 2019 - 2024. All rights reserved.