您可以使用模板选项
<p-column>
<ng-template let-col let-car="rowData" pTemplate="body">
<input type="checkbox" [disabled]="true"/>
</ng-template>
</p-column>
更新1:
<p-dataTable (onRowSelect)="rowSelected($event)"
[value]="tableData" [(selection)]="selectedData" dataKey="model" [responsive]="true">
<p-column>
<ng-template let-col let-car="rowData" pTemplate="body">
<input type="checkbox" [checked]="car.status" [(ngModel)]="car.status" (change)="checked(car)"/>
</ng-template>
</p-column>
<p-column field="orderNumber" header="Order Number"></p-column>
<p-column field="country" header="Country"></p-column>
</p-dataTable>
选定项目
checked(carValue){
console.log(carValue)
if(carValue.status){
this.selectedData.push(carValue);
}else {
_.remove(this.selectedData, function(val) {return val === carValue;})
}
Demo 相应更新
LIVE DEMO
更新 1:检查并检查所有
<p-dataTable (onRowSelect)="rowSelected($event)"
[value]="tableData" [responsive]="true">
<p-column>
<ng-template pTemplate="header">
<input type="checkbox" [ngModel]="checkedAll" (ngModelChange)="checkAll($event)"/>
</ng-template>
<ng-template let-col let-car="rowData" pTemplate="body">
<input type="checkbox" *ngIf="!car.disabled" [(ngModel)]="car.status" (change)="checked(car)"/>
<input type="checkbox" *ngIf="car.disabled" [checked]="false" disabled (change)="checked(car)"/>
</ng-template>
</p-column>
<p-column field="orderNumber" [header]="'Order Number'"></p-column>
<p-column field="country" [header]="'Country'"></p-column>
</p-dataTable>
打字稿代码
checked(carValue){
if(carValue.status){
this.selectedData.push(carValue);
}else {
_.remove(this.selectedData, function(val) {return val === carValue;})
}
console.log(this.selectedData)
}
checkAll(event){
_.forEach(this.tableData =>(item){
if(event){
item.status=true;
}else {
item.status=false;
}
});
this.selectedData= this.tableData;
if(!event){
this.selectedData = [];
}
console.log(this.selectedData);
}
现场演示