Angular 在素数数据表/类型脚本中转置数据

Angular 在素数数据表/类型脚本中转置数据,angular,typescript,primeng,Angular,Typescript,Primeng,我有一系列的地方都有这些田地。(大陆和国家) 如果我在一个素数数据表中绘制它,它是这样的。 我想要的是转换数据。我希望datatable在datatable中以这样的方式显示:大陆行将成为标题,国家将成为字段。我想要的是这样的 我为此创建了一个plunkr 修改您的plunkr使其工作 html- <p-dataTable [value]="places" sortMode="single" reorderableColumns="true" [globalFilter]="gb" s

我有一系列的地方都有这些田地。(大陆和国家)

如果我在一个素数数据表中绘制它,它是这样的。

我想要的是转换数据。我希望datatable在datatable中以这样的方式显示:大陆行将成为标题,国家将成为字段。我想要的是这样的


我为此创建了一个plunkr

修改您的plunkr使其工作

html-

<p-dataTable [value]="places" sortMode="single" reorderableColumns="true" [globalFilter]="gb" scrollable="true" scrollHeight="350px">
  <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header" [sortable]="true" [style]="{'width': '200px'}">
  </p-column>
</p-dataTable>

可能是@Aravind的副本你能检查一下我的枪吗?我正试图做到这一点,但我不知道如何实现它。
<p-dataTable [value]="places" sortMode="single" reorderableColumns="true" [globalFilter]="gb" scrollable="true" scrollHeight="350px">
  <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header" [sortable]="true" [style]="{'width': '200px'}">
  </p-column>
</p-dataTable>
export class AppComponent {
  places_rawdata = 
          [
           { "continent":"Europe", "country": "UK" },
           { "continent":"North America", "country": "US" },
           { "continent":"Asia", "country": "Philippines" },
           { "continent":"Africa", "country": "Egypt" }
          ];

  places: any [] = [];
  cols:any[]=[];

  ngOnInit() {
    let temp: any = {};
    this.places=[];
    this.places_rawdata.forEach(
     (place,index) => {
       let s : string = 'country' + index;
       temp[s]= place.country
       this.cols.push({field: s, header: place.continent})
    });
    this.places = [...this.places,temp];
    console.log(this.places);
  }
}