|
App.component.html
<ejs-grid [dataSource]="transposedData" [allowSelection]="false" [enableHover]="false" cssClass="hide-header">
<e-columns>
<e-column *ngFor="let col of columns">
<ng-template #template let-data>
<span>{{ data[col] }}</span>
</ng-template>
</e-column>
</e-columns>
</ejs-grid>
App.component.ts
export class AppComponent {
public columns: string[] = [];
public transposedData: any[] = [];
ngOnInit(): void {
const data = this.getOrdersDetails();
const transposedTable = this.transposeDataTable(data);
this.columns = Object.keys(transposedTable[0]);
this.transposedData = transposedTable;
}
getOrdersDetails() {
return [
{ OrderID: 10248, CustomerID: 'VINET', EmployeeID: 5 },
{ OrderID: 10249, CustomerID: 'TOMSP', EmployeeID: 6 },
];
}
transposeDataTable(data: any[]) {
const output: any[] = [];
const keys = Object.keys(data[0]);
keys.forEach((key, colIndex) => {
const row: any = { [keys[0]]: key };
data.forEach((item, rowIndex) => {
row[`Col${rowIndex + 1}`] = item[key];
});
output.push(row);
});
return output;
}
}
|