PrimeNG数据表cols与嵌套的json对象

时间:2017-10-04 15:33:49

标签: angular datatable primeng

我有一个使用PrimeNG p-datatable创建表的指令:

<p-dataTable paginatorPosition="top" scrollable="true" scrollHeight="200px" 
   [value]="table.cells" resizableColumns="true" [loading]="loading">
            <p-column *ngFor="let col of table.headers" [field]="col.field" [header]="col.header" [sortable]="col.sortable" [style]="{'width':'230px'}">
                ...

在服务内部创建一个这样的实体:

        header = new MyTableHeaders();
        header.header = "Col Head"
        header.field = "field";
        header.sortable = false;
...

当我有一个嵌套对象传入时,就像这样:

name: "name",
address: {
   city: "city",
   street: "street",
   ...

我试图通过:

header = new MyTableHeaders();
header.header = "Col Head"
header.field = "address.city";
header.sortable = false;

header = new MyTableHeaders();
header.header = "Col Head"
header.field = "address[city]";
header.sortable = false;

但是col中没有值。你能帮助我吗? 感谢

1 个答案:

答案 0 :(得分:-1)

我认为您必须更改您的p列以包含ng-template ... 看看

<p-column field="Sessions" [editable]="true" header="Start Date">              
    <ng-template let-col let-sessions="rowData" let-ri="rowIndex" pTemplate="body">
     <div>
       <p>{{sessions.Sessions[0].StartDateTime | date: 'd,MMM,yyyy'}}</p>
      </div>
    </ng-template>
</p-column>

举个例子。另请参阅here