Angular 素数表p-表,设置条件列可编辑
我在angular 7应用程序中使用Priming p-table控件。 下面是我正在使用的html代码:Angular 素数表p-表,设置条件列可编辑,angular,primeng,primeng-turbotable,Angular,Primeng,Primeng Turbotable,我在angular 7应用程序中使用Priming p-table控件。 下面是我正在使用的html代码: <p-table [value]="data" [reorderableColumns]="'true'" [columns]="cols"> <ng-template pTemplate="header" let-columns> <tr> <th *ngFor="let col of columns" pReorder
<p-table [value]="data" [reorderableColumns]="'true'" [columns]="cols">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" pReorderableColumn>
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td [pEditableColumn] *ngFor="let col of columns" [ngSwitch]="col.field">
<p-cellEditor *ngSwitchCase="'TYPE'">
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
<p-cellEditor *ngSwitchCase="'CEPCODE'">
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
<p-cellEditor *ngSwitchCase="'HRS'">
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</td>
</tr>
</ng-template>
{{col.header}}
{{rowData[col.field]}
{{rowData[col.field]}
{{rowData[col.field]}
运行应用程序时,表如下所示:
在我的上表中,“类型”列不可编辑,其他所有列都可编辑。我想知道如何为td动态设置[pEditableColumn](如果column为type,则不要设置[pEditableColumn])此功能在早期版本的Priming中就已经存在,并且易于实现,但是,您可以使用以下方法 可以向列配置添加一个属性,如col.editable 组件。ts
import { Component } from "@angular/core";
import { FormBuilder } from "@angular/forms";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
cols = [];
data = [];
constructor() {
this.cols = [
{ header: "TYPE", field: "TYPE", editable: false },
{ header: "CEPCODE", field: "CEPCODE", editable: true },
{ header: "HRS", field: "HRS", editable: true }
];
this.data = [{ HRS: "HRS1", TYPE: "OMEGA", CEPCODE: "YTMMETRE" }];
}
}
.disable-td{
pointer-events: none;
}
基于此,您可以在动态添加模板时更改模板。
component.html
<p-table [value]="data" [reorderableColumns]="'true'" [columns]="cols">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" pReorderableColumn>
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns" [pEditableColumn] [ngClass]="{'disable-td' : !col.editable}" >
<div *ngIf="!col.editable">
{{rowData[col.field]}}
</div>
<p-cellEditor *ngIf="col.editable">
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</td>
</tr>
</ng-template>
</p-table>
模板代码删除为简洁 最后我找到了下面的工作区(使用单元格导航进行内联编辑)
{{col.headerName}
{{rowData[col.field]}
{{rowData[col.field]}
{{rowData[col.field]}
{{rowData[col.field]}
{{rowData[col.field]}
{{rowData[col.field]}
{{rowData[col.field]}
{{rowData[col.field]}
{{rowData[col.field]}
是的,我们可以像你提到的那样做。但在您的解决方案中,单元格导航并没有按照我的要求工作。例如,如果有2行,则在从Hrs字段的选项卡上,我希望焦点应转到下一行的CEPCODE。请参阅下面的fork URL:
<p-table (sortFunction)="customSort($event)" [customSort]="true" [scrollable]="true" scrollHeight="650px" class="png-table"
[value]="data" [reorderableColumns]="'false'" [resizableColumns]="'false'" [columns]="cols">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" [pSortableColumn]="col.field" [style.width.px]="getColumnWidth(col)" [hidden]="col.hide"
pResizableColumn pReorderableColumn [class]="col.filter?'sortable':'non-sortable'">
{{col.headerName}}
<p-sortIcon [field]="col.field"></p-sortIcon>
</th>
</tr>
<tr class="filter-row" *ngIf="1==2">
<th *ngFor="let col of columns" [hidden]="col.hide">
<input class="filter-input" *ngIf="col.filter" pInputText type="text" (input)="dt.filter($event.target.value, col.field, 'contains')">
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<ng-container *ngFor="let col of columns" [ngSwitch]="col.type">
<td *ngSwitchCase="'del'" [style.width.px]="getColumnWidth(col)">
<i class="fa fa-close delete-icon g-act-icon" (click)='deleteRow()'></i>
</td>
<td *ngSwitchCase="'edit'" [style.width.px]="getColumnWidth(col)">
<i class="fa fa-edit edit-icon g-act-icon" (click)='deleteRow()'></i>
</td>
<td *ngIf="!col.hide && col.type=='type'" [style.width.px]="getColumnWidth(col)">
{{rowData[col.field]}}
</td>
<td [pEditableColumn] *ngSwitchCase="'cep'" [style.width.px]="getColumnWidth(col)">
<p-cellEditor>
<ng-template pTemplate="input">
<p-inputMask (keyup)="onEnterCEP()" [(ngModel)]="rowData[col.field]" mask="aaaaaa-999-999"></p-inputMask>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</td>
<td [hidden]="col.hide" *ngSwitchCase="'cb'" [style.width.px]="getColumnWidth(col)">
{{rowData[col.field]}}
</td>
<td *ngIf="!col.hide && col.type=='act'" [pEditableColumn] [style.width.px]="getColumnWidth(col)">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</td>
<td [pEditableColumn] *ngIf="!col.hide && col.type=='com'" [style.width.px]="getColumnWidth(col)">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</td>
<td [pEditableColumn] *ngIf="!col.hide && col.type=='tsk'" [style.width.px]="getColumnWidth(col)">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</td>
<td [pEditableColumn] *ngIf="!col.hide && col.type=='sco'" [style.width.px]="getColumnWidth(col)">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</td>
<td [pEditableColumn] *ngSwitchCase="'hrs'" [style.width.px]="getColumnWidth(col)">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="rowData[col.field]" >
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</td>
<td [hidden]="col.hide" [pEditableColumn] *ngSwitchCase="'des'" [style.width.px]="getColumnWidth(col)">
<p-cellEditor>
<ng-template pTemplate="input">
<input pInputText type="text" [(ngModel)]="rowData[col.field]" required>
</ng-template>
<ng-template pTemplate="output">
{{rowData[col.field]}}
</ng-template>
</p-cellEditor>
</td>
</ng-container>
</tr>
</ng-template></p-table>