Make newObject deletable

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

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

@ -261,11 +261,23 @@ export class BikesComponent {
this.bikesService.loadBikes(); this.bikesService.loadBikes();
} }
addEmptyRow() { addNewObject() {
this.paginator.firstPage(); this.paginator.firstPage();
this.resetFilter(); this.resetFilter();
this.resetSorting(); 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) { create(row: any) {

Loading…
Cancel
Save