I'm using angular 15.1 with angular material, I use angular material Table component to show tables.
my project have like 20 different tables that share 90% percent of the columns definitions so i would to place the shared columns in a ng-template instead of redefining the shared columns over and over again.
so I created the following template:
<ng-template #stats_common_columns>
<ng-container matColumnDef="col1">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Header1 </th>
<td mat-cell *matCellDef="let element"> {{element['col1']}} </td>
</ng-container>
<ng-container matColumnDef="col2">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Header2 </th>
<td mat-cell *matCellDef="let element"> {{element['col2']}} </td>
</ng-container>
...
</ng-template>
and then in the table definition i do the following:
<table [ngStyle]="{'display': isLoading ? 'none' : 'block'}" mat-table
matSort #sortedAgentTableTop="matSort" multiTemplateDataRows
[dataSource]="dataSource"
class="mat-elevation-z8">
<ng-container *ngTemplateOutlet="stats_common_columns"></ng-container>
....
</table>
unfortunately for all the ng-template related columns i get the error Could not find column with id X
so obviously this is not the way to go.
well i actually want the ng-template columns to be in a separate file to be loaded by the other table components but for now i'm trying on the same file just to understand how it works.
any ideas?