PrimeNG TurboTable : Does dataKey need to be a column?

标签 primeng primeng-turbotable

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

最佳答案

不,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>

typescript :
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

关于PrimeNG TurboTable : Does dataKey need to be a column?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49560815/

相关文章:

css - PrimeNG - p 面板的样式大小和对齐方式

angular - PrimeNg DropDown - 用户无法清除该值

html - float 标签在 Firefox 上不起作用

angular - 如何禁用 TurboTable 组件上取消选择行的选项?

angular7 - PrimeNG 表列排序不起作用

angular - 如何隐藏 PrimeNG turbo 表中的列?

angular - onEditComplete 不起作用

angular - 可以在可排序的 primeng 表中更改列的宽度吗?

angular - primeng 复选框 ngmodel 不是已知属性

css - 更改内部类样式以溢出 : visible for specific class (For PrimeNG)