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

Commit bb62c0a

Browse files
Ghislain BeaulacGhislain Beaulac
Ghislain Beaulac
authored and
Ghislain Beaulac
committed
fix(updateItem): call grid.updateRow instead of grid.invalidateRow
- triggering invalidateRow will destroy any opened editor, so we should not call it and the correct method to use after updating a row is to use grid.updateRow - SlickGrid author mentioned the following: You would typically use invalidateRows()/invalidateRow() followed by render() to update the data. The updateRow()/updateCell() are there in case you absolutely have to keep the existing DOM objects instead of recreating them.
1 parent f3b9de4 commit bb62c0a

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,7 @@ export class AngularSlickgridComponent implements AfterViewInit, OnDestroy, OnIn
472472

473473
if (dataView && grid) {
474474
this._eventHandler.subscribe(dataView.onRowCountChanged, (e: any, args: any) => {
475-
grid.updateRowCount();
476-
grid.render();
477-
});
478-
this._eventHandler.subscribe(dataView.onRowsChanged, (e: any, args: any) => {
479-
grid.invalidateRows(args.rows);
480-
grid.render();
475+
grid.invalidate();
481476
});
482477
}
483478

src/app/modules/angular-slickgrid/services/grid.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ export class GridService {
242242
throw new Error('We could not find SlickGrid Grid, DataView objects');
243243
}
244244

245-
const row = 0;
246-
this._dataView.insertItem(row, item);
245+
this._dataView.insertItem(0, item); // insert at index 0
247246

248247
if (!shouldResortGrid) {
249248
this._grid.scrollRowIntoView(0); // scroll to row 0
@@ -445,20 +444,21 @@ export class GridService {
445444
if (itemId === undefined) {
446445
throw new Error(`Cannot update a row without a valid "id"`);
447446
}
448-
const row = this._dataView.getRowById(itemId);
447+
const rowNumber = this._dataView.getRowById(itemId);
449448

450-
if (!item || row === undefined) {
449+
if (!item || rowNumber === undefined) {
451450
throw new Error(`Could not find the item in the grid or it's associated "id"`);
452451
}
453452

454453
const gridIdx = this._dataView.getIdxById(itemId);
455454
if (gridIdx !== undefined) {
456455
// Update the item itself inside the dataView
457456
this._dataView.updateItem(itemId, item);
457+
this._grid.updateRow(rowNumber);
458458

459459
// highlight the row we just updated, if defined
460460
if (shouldHighlightRow) {
461-
this.highlightRow(row, 1500);
461+
this.highlightRow(rowNumber, 1500);
462462
}
463463

464464
// do we want to trigger an event after updating the item

0 commit comments

Comments
 (0)