Skip to content

Commit

Permalink
fix(example): use highest id as new id in addItem example, fixes #495 (
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Jun 17, 2020
1 parent 48b3258 commit 1550d9d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/app/examples/grid-additem.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 1550d9d

Please sign in to comment.