Table with dynamic columns - footer / header does not update after context change
See original GitHub issueBug, feature request, or proposal:
Bug
What is the expected behavior?
I define table using dynamic columns like below. In footer cell definition I am using some context object (from current component) and its values.
After context object is updated, table footer displays current data.
<ng-container
*ngFor="let month of months;"
matColumnDef="p{{month}}"
>
<th mat-header-cell *matHeaderCellDef>
{{month}}
</th>
<td
mat-cell
*matCellDef="let element"
>
{{element.someValue}}
</td>
<td mat-footer-cell *matFooterCellDef>
{{someContextObject?.someValue}}
</td>
</ng-container>
What is the current behavior?
After updating context object, table footer does not show changes. It does not work even, if context variable is a simple string.
This works correctly, if table cell is not defined using *ngFor
.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular Material 6.4.7
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:9 (3 by maintainers)
Top Results From Across the Web
<table> with fixed <thead> and scrollable <tbody> [duplicate]
have scrollable <tbody> (scrollbar may be always visible); header and body would handle resizing properly and not mess alignment of the <thead> columns...
Read more >Excel header and footer: how to add, change and remove
Change header or footer in Page Layout view To switch to Page Layout view, go to the View tab > Workbook Views group,...
Read more >Tables Tutorial | Web Accessibility Initiative (WAI) - W3C
Tables with irregular headers have header cells that span multiple columns and/or rows: For these tables, define column and row groups and set...
Read more >Insert a table of contents - Microsoft Support
Add an easy to maintain Table of Contents using heading styles that automatically updates when you make changes to your headings.
Read more >Table | Angular Material
Each column definition can contain a header-cell template ... you want rendered (e.g. if you do not need a footer row, simply do...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Further to the issues noted by @literalpie above, I have more workarounds for those interested.
Having noted the ‘changed’ flags as part of
removeHeaderRowDef()
andremoveFooterRowDef()
https://github.com/angular/material2/blob/21e646a3e7d99323e3f6d1e2961f416c8695bf48/src/cdk/table/table.ts#L555 https://github.com/angular/material2/blob/21e646a3e7d99323e3f6d1e2961f416c8695bf48/src/cdk/table/table.ts#L567here are some change detection workarounds for header/footer rows:
ngIf
d --> usetable.removeHeaderRowDef(null)
to trigger an update to the header (ortable.removeFooterRowDef(null)
)See updated stackblitz - note that toggling
booly
refreshes table header and body rows correctly.Update - I have been able to make a work around for this using separate ng-template (outside of ng-container), like below. But this is absurd, especially for footer cells, which often show aggregate values (totals) from outside of table data source.