class ProvinciaComponent extends CatalogoGenerico implements OnInit,
AfterViewInit {
page: Page = new Page({sort: {field: 'description', dir: 'asc'}});
dataSource: ProvinciaDataSource;
columns = ['codprovince', 'codprovinciasc', 'description', 'country.codcountry','country.description'];
labelColumns = {
'codprovince': {'label': 'Code', 'width': '60', 'align': '', 'format': ''},
'codprovinciasc': {'label': 'INEC Code', 'width': '60', 'align': '', 'format': ''},
'description': {'label': 'Description', 'width': '60', 'align': '', 'format': ''},
'country.codcountry': {'label': 'Country Code', 'width': '60', 'align': '', 'format': ''},
'country.description': {'label': 'Country', 'width': '60', 'align': '', 'format': ''}
};
headerColumns = this.columns.concat(['actions']);
displayedColumns = this.headerColumns;
}
and the template used is as follows:
<mat-table [dataSource]="dataSource" matSort matSortActive="description" matSortDirection="asc"
matSortDisableClear>
<ng-container [cdkColumnDef]="column" *ngFor="let column of columns">
<mat-header-cell *matHeaderCellDef mat-sort-header>{{labelColumns[column].label}}</mat-header-cell>
<mat-cell *matCellDef="let element"> {{element[column]}} </mat-cell>
</ng-container>
<!-- Column Definition: actions -->
<ng-container matColumnDef="actions">
<mat-header-cell *matHeaderCellDef>Actions</mat-header-cell>
<mat-cell *matCellDef="let row; let i=index;">
<div class="actions">
<button mat-icon-button [matMenuTriggerFor]="menu" aria-label="Open basic menu"
[disabled]="!permiso.is_edit && !permiso.is_remove">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item (click)="openPopUp(row, row.idprovincia)"
*ngIf="permiso.is_edit">
<mat-icon>edit</mat-icon>
<span>Edit</span>
</button>
<button mat-menu-item (click)="eliminarProvincia(row)"
*ngIf="permiso.is_remove">
<mat-icon>delete</mat-icon>
<span>Delete</span>
</button>
</mat-menu>
</div>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns;"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table>
The diagram displaying the data structure can be viewed here:
https://i.stack.imgur.com/pWHHo.png
In order to access specific attributes of the country object in the row data, such as 'country.codcountry', you may need a different approach considering how the keys are defined within the component's array. Hope that helps.
columns = ['codprovince', 'codprovinciasc', 'description', 'country.codcountry', 'country.description'];