I am currently working on an Angular 7 project where I have implemented a basic component that utilizes an Angular Material Table. I want to be able to update both the data and the header of the table when a certain event occurs, such as a mouse click.
Before:
https://i.sstatic.net/B0Unj.png
After (goal):
https://i.sstatic.net/6Y6HV.png
Currently, I have been successful in updating the data, but I am facing issues with updating the header text of the columns. I have tried using a window timeout call, which seems like a hacky solution.
It is difficult to explain this issue clearly, so I have provided a link to a stackblitz repository for reference. In the 'table-dynamic-columns.example.ts' file, you can see the two different strategies I have attempted in the 'changeColumnHeader' button click handler. It seems that clearing out the displayed columns of the table first and then setting them back within a timeout is necessary for the new column header title to appear properly. Perhaps the problem lies in the fact that only the title changes while the property name ('id') remains the same.
Is there a more efficient way to achieve this desired update?