Make newObject deletable

urls
Max Ehrlicher-Schmidt 4 years ago
parent 20eaf2ba85
commit daeb4b1a0a

@ -15,7 +15,7 @@
<button
mat-raised-button
class="table-control-button"
(click)="addEmptyRow()"
(click)="addNewObject()"
[disabled]="reloadingTable"
>
<mat-icon class="spin">add</mat-icon>
@ -154,6 +154,13 @@
>
<mat-icon>save</mat-icon>
</button>
<button
mat-icon-button
matTooltip="Verwerfen"
(click)="deleteNewObject(element)"
>
<mat-icon>delete</mat-icon>
</button>
</div>
</td>
</ng-container>

@ -261,11 +261,23 @@ export class BikesComponent {
this.bikesService.loadBikes();
}
addEmptyRow() {
addNewObject() {
this.paginator.firstPage();
this.resetFilter();
this.resetSorting();
this.data.data = [{ newObject: true }, ...this.data.data];
this.data.data = [{ newObject: true, id: this.getNewId() }, ...this.data.data];
}
getNewId(): string {
let id = -1;
while(this.getRowById(id.toString())) {
id--;
}
return id.toString();
}
deleteNewObject(row: any) {
this.data.data = this.data.data.filter(element => row.id !== element.id);
}
create(row: any) {

Loading…
Cancel
Save