我正在使用PrimeNG TurboTable,我希望在PrimeNG Turbotable中的输入模板中集成p-dropdown
组件。问题是当我使用以下代码时,无法将所选元素分配给值表。
<ng-template pTemplate="body" let-rowData let-row="rowIndex">
<tr>
<td>{{listRow[row]}}</td>
<ng-container *ngIf="edit">
<td pEditableColumn *ngFor="let col of listCol; let i = index">
<p-cellEditor>
<ng-template pTemplate="input">
<p-dropdown [options]="eltList" [(ngModel)]="rowData[i]"></p-dropdown>
</ng-template>
<ng-template pTemplate="output">
{{rowData[i]}}
</ng-template>
</p-cellEditor>
</td>
</ng-container>
<ng-container *ngIf="!edit">
<td *ngFor="let col of listCol; let i = index">{{rowData[i]}}</td>
</ng-container>
</tr>
</ng-template>
答案 0 :(得分:0)
这是一个有效的例子:
<ng-template pTemplate="body" let-rowData let-columns="columns" let-rowIndex="rowIndex">
<tr>
<td [ngStyle]="{'width':'10%'}">{{rowIndex+1}}</td>
<td *ngFor="let col of columns" pEditableColumn [ngSwitch]="col.field">
<div *ngSwitchCase="'color'">
<p-cellEditor>
<ng-template pTemplate="input">
<p-dropdown appendTo="body" [options]="colors" [(ngModel)]="rowData[col.field]" [style]="{'width':'100%'}"></p-dropdown>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</div>
<div *ngSwitchDefault>
<p-cellEditor>
<ng-template pTemplate="input">
<input type="text" [(ngModel)]="rowData[col.field]">
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</div>
</td>
</tr>
</ng-template>