From daeb4b1a0ae2e5607c641c82473613eaa3c8c529 Mon Sep 17 00:00:00 2001 From: Max Ehrlicher-Schmidt Date: Wed, 18 Nov 2020 18:28:37 +0100 Subject: [PATCH] Make newObject deletable --- src/app/pages/tables/bikes/bikes.component.html | 9 ++++++++- src/app/pages/tables/bikes/bikes.component.ts | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/app/pages/tables/bikes/bikes.component.html b/src/app/pages/tables/bikes/bikes.component.html index 9271fd9..cdbca50 100644 --- a/src/app/pages/tables/bikes/bikes.component.html +++ b/src/app/pages/tables/bikes/bikes.component.html @@ -15,7 +15,7 @@ + diff --git a/src/app/pages/tables/bikes/bikes.component.ts b/src/app/pages/tables/bikes/bikes.component.ts index 125f257..89454a3 100644 --- a/src/app/pages/tables/bikes/bikes.component.ts +++ b/src/app/pages/tables/bikes/bikes.component.ts @@ -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) {