Use angular-material table. Generate the column array for the table by pushing all the keys of a single row into it. i.e
my-component.component.ts
import { Component, OnInit } from '@angular/core';
import {MatPaginator, MatSort, MatTableDataSource} from '@angular/material';
@Component({
selector: 'blank',
templateUrl: './blank.component.html',
styleUrls: ['./blank.component.scss']
})
export class MyComponent implements OnInit {
yourColumns: string[] = [];
data: any[] = data_array_from_your_file;
dataSource: any = new MatTableDataSource(this.data);
constructor() {
for(let i=0; i < this.data.length; i++) {
let row = this.data[i];
for(let key of Object.keys(row)) {
this.yourColumns.push(key);
}
break; //one row is enough to be used as a reference assuming the dataset is uniform
}
ngOnInit() {
}
}
my-component.component.html
<div>
<table [dataSource]="dataSource" mat-table matSort>
<!-- Column -->
<ng-container *ngFor="let tColumn of yourColumns" matColumnDef="{{tColumn}}">
<th *matHeaderCellDef mat-header-cell mat-sort-header> {{tColumn}}</th>
<td *matCellDef="let row" mat-cell> {{row[tColumn] }} </td>
</ng-container>
<tr *matHeaderRowDef="yourColumns" mat-header-row></tr>
<tr *matRowDef="let row; columns: yourColumns;" mat-row>
</tr>
</table>
</div>