From c8fde57a995ac6c8eb223bf9c842371b71d8fd99 Mon Sep 17 00:00:00 2001 From: Ghislain Beaulac Date: Tue, 16 Jun 2020 11:31:36 -0400 Subject: [PATCH] fix(example): use highest id as new id in addItem example, fixes #495 --- src/app/examples/grid-additem.component.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/examples/grid-additem.component.ts b/src/app/examples/grid-additem.component.ts index 9913e4251..04e1a307d 100644 --- a/src/app/examples/grid-additem.component.ts +++ b/src/app/examples/grid-additem.component.ts @@ -164,7 +164,14 @@ export class GridAddItemComponent implements OnInit { } addNewItem(insertPosition?: 'top' | 'bottom') { - const newId = this.dataset.length; + const dataset = this.angularGrid.dataView.getItems(); + let highestId = 0; + dataset.forEach(item => { + if (item.id > highestId) { + highestId = item.id; + } + }); + const newId = highestId + 1; const randomYear = 2000 + Math.floor(Math.random() * 10); const randomMonth = Math.floor(Math.random() * 11); const randomDay = Math.floor((Math.random() * 29));