【问题标题】:PrimeNG TurboTable: Does dataKey need to be a column?PrimeNG TurboTable:dataKey 需要是列吗?
【发布时间】:2018-09-08 16:36:04
【问题描述】:

是否需要将 p-table 上的 dataKey 属性定义为列,还是只需将其作为 [value] 数组中对象的属性?如果它需要是一个列,这个列是否需要可见?

【问题讨论】:

  • 对象的一个​​属性就够了。
  • 这个数据键实际上是什么意思?

标签: primeng primeng-turbotable


【解决方案1】:

不,dataKey 不需要是列。

dataKey 应该是记录的一个属性,但它不需要显示出来就可以被表格使用。

HTML:

<p-table [columns]="cols" [value]="cars" [(selection)]="selectedCars" dataKey="vin">

    <ng-template pTemplate="header" let-columns>
        <th *ngFor="let col of columns">
            {{col.header}}
        </th>
    </ng-template>

    <ng-template pTemplate="body" let-car>
        <tr>
            <td>{{car.year}}</td>
        </tr>
    </ng-template>

</p-table>

打字稿:

export class TableDemo implements OnInit {

    cars: Car[];

    cols: any[];

    constructor() { }

    ngOnInit() {
        this.cars = [
            { vin: '123ABC', year: 1994 },
            { vin: '234BCD', year: 1978 },
            { vin: '345CDE', year: 2015 },
        ];

        this.cols = [
            { field: 'year', header: 'Year' }
        ];
    }
}

PrimeNG Table Documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-11
    • 2022-01-19
    • 2011-11-20
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 2021-06-08
    • 2012-07-21
    相关资源
    最近更新 更多