【发布时间】:2021-04-23 09:47:18
【问题描述】:
我有一个可内联编辑的表格,当我单击特定行的编辑按钮时,我想隐藏所有其他行的“编辑”和“删除”按钮。我尝试使用当前索引,但它对我不起作用。当我点击addNew 按钮时也是如此
<a (click)="addNew()" class="mb-1 ml-1">Add New</a>
<table class="row-border table-bordered-no-confilct border-1 table">
<thead>
<tr>
<th *ngFor="let head of headers">
{{ head.name }} <span class="text-danger" *ngIf="head.required">*</span>
</th>
</tr>
</thead>
<tr *ngFor="let tableData of data; let i = index">
<td>
<div *ngIf="i">
<i
class="ace-icon fa fa-pencil-square-o bigger-150 text-success"
data-toggle="tooltip"
title="Edit"
*ngIf="!tableData.isEditable"
(click)="onEdit(tableData)"
></i>
<i
class="ace-icon fa fa-trash-o bigger text-danger ml-1"
data-toggle="tooltip"
title="Delete"
*ngIf="!tableData.isEditable"
(click)="onDelete(tableData)"
></i>
</div>
<i
class="ace-icon fa fa-floppy-o bigger-150 text-success"
data-toggle="tooltip"
title="Save"
*ngIf="tableData.isEditable"
(click)="onSave(tableData)"
></i>
<i
class="ace-icon fa fa-times bigger-150 text-danger ml-1"
data-toggle="tooltip"
title="Cancel"
*ngIf="tableData.isEditable"
(click)="cancel(tableData, i)"
></i>
</td>
<td>{{ i + 1 }}</td>
<ng-container *ngIf="tableData.isEditable; else viewable">
<ng-container *ngFor="let head of headers">
<ng-container *ngIf="head.mappedProperty">
<td>
<input
*ngIf="
head.dataType === 'text' ||
head.dataType === 'number' ||
head.dataType === 'checkbox'
"
[type]="head.dataType"
[(ngModel)]="tableData[head.mappedProperty]"
[checked]="tableData[head.mappedProperty]"
/>
</td>
</ng-container>
</ng-container>
</ng-container>
<ng-template #viewable>
<ng-container *ngFor="let head of headers">
<ng-container *ngIf="head.mappedProperty">
<td>{{ tableData[head.mappedProperty] }}</td>
</ng-container>
</ng-container>
</ng-template>
</tr>
</table>
ts
onEdit(data): void {
this.isNew = false;
this.copyOfOriginalData = { ...data };
this.data.map((item) => {
item.isEditable = data.id === item.id;
});
}
【问题讨论】:
标签: javascript angular typescript