Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 154bfb1

Browse files
authored
feat(core): use DataView transactions with multiple item changes (#527)
* feat(core): use DataView transactions with multiple item changes - we should use DataView transactions as much as possible when dealing with multiple items (array) in 1 call, that is true for (addItems, deleteItems, updateItems)
1 parent 36f958d commit 154bfb1

File tree

4 files changed

+111
-5
lines changed

4 files changed

+111
-5
lines changed

src/app/examples/grid-additem.component.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,31 @@ export class GridAddItemComponent implements OnInit {
164164
}
165165

166166
addNewItem(insertPosition?: 'top' | 'bottom') {
167+
const newItem1 = this.createNewItem(1);
168+
const newItem2 = this.createNewItem(2);
169+
170+
// single insert
171+
this.angularGrid.gridService.addItem(newItem1, { position: insertPosition });
172+
173+
// OR multiple inserts
174+
// this.angularGrid.gridService.addItems([newItem1, newItem2], { position: insertPosition });
175+
}
176+
177+
createNewItem(incrementIdByHowMany = 1) {
167178
const dataset = this.angularGrid.dataView.getItems();
168179
let highestId = 0;
169180
dataset.forEach(item => {
170181
if (item.id > highestId) {
171182
highestId = item.id;
172183
}
173184
});
174-
const newId = highestId + 1;
185+
const newId = highestId + incrementIdByHowMany;
175186
const randomYear = 2000 + Math.floor(Math.random() * 10);
176187
const randomMonth = Math.floor(Math.random() * 11);
177188
const randomDay = Math.floor((Math.random() * 29));
178189
const randomPercent = Math.round(Math.random() * 100);
179190

180-
const newItem = {
191+
return {
181192
id: newId,
182193
title: 'Task ' + newId,
183194
duration: Math.round(Math.random() * 100) + '',
@@ -187,7 +198,6 @@ export class GridAddItemComponent implements OnInit {
187198
finish: new Date(randomYear, (randomMonth + 2), randomDay),
188199
effortDriven: true
189200
};
190-
this.angularGrid.gridService.addItem(newItem, { position: insertPosition });
191201
}
192202

193203
highlighFifthRow() {
@@ -249,7 +259,7 @@ export class GridAddItemComponent implements OnInit {
249259
const updatedItem2 = this.angularGrid.gridService.getDataItemByRowNumber(2);
250260
updatedItem1.duration = Math.round(Math.random() * 100);
251261
updatedItem2.duration = Math.round(Math.random() * 100);
252-
this.angularGrid.gridService.updateItems([updatedItem1, updatedItem2], true);
262+
this.angularGrid.gridService.updateItems([updatedItem1, updatedItem2], { highlightRow: true });
253263
*/
254264
}
255265

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,6 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
378378

379379
if (dataset) {
380380
this.grid.invalidate();
381-
this.grid.render();
382381
}
383382

384383
// display the Pagination component only after calling this refresh data first, we call it here so that if we preset pagination page number it will be shown correctly

0 commit comments

Comments
 (0)