angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.37k stars 6.75k forks source link

bug(mat-table): matFooterCellDef not showing updated value when changed #26237

Open eneajaho opened 1 year ago

eneajaho commented 1 year ago

Is this a regression?

The previous version in which this bug was not present was

No response

Description

When creating dynamic tables using mat-table and it's directives, I expect to pass data to the dynamic component and it to rerender everything based on data.

<table [dataSource]="data" mat-table>
  <ng-container
    *ngFor="let column of columns"
    [matColumnDef]="column.columnDef">
    <th *matHeaderCellDef mat-header-cell mat-sort-header>
      {{ column.header }}
    </th>
    <td *matCellDef="let row" mat-cell>
      {{ column.cell(row) }}
    </td>
    <td *matFooterCellDef mat-footer-cell>
      {{ column.footer }}
    </td>
  </ng-container>

  <tr *matHeaderRowDef="displayedColumns" mat-header-row></tr>
  <tr *matRowDef="let row; columns: displayedColumns" mat-row></tr>
  <ng-container *ngIf="showFooterRow">
    <tr *matFooterRowDef="displayedColumns" mat-footer-row></tr>
  </ng-container>
</table>

Reproduction

Reproduction: https://stackblitz.com/edit/angular-ivy-6urypw?file=src%2Fapp%2Ftest-table.component.ts

Expected Behavior

I expect to see an updated table based on the data I pass to it, and not only stuff inside matCellDef, but also inside matFooterCellDef and matHeaderCellDef.

Actual Behavior

Updating data for matCellDef works, but it doesn't re-render and update data inside matFooterCellDef and matHeaderCellDef.

Environment

Angular v14 and v15

eneajaho commented 1 year ago

There was also this issue: https://github.com/angular/components/issues/13030 but it's closed because of missing reproduction.

pookdeveloper commented 1 month ago

By default I have a variable that hides a footer and after 200 seconds I enable it as shown in the example it does not render it, the colum def is itemFooter

alternateFooter: string[] = ['itemFooter', 'costFooter'];