Skip to content

Commit fb8a813

Browse files
hanastasovkdinev
andauthored
fix(grid): trigger pipes with markForCheck call (#9470)
Co-authored-by: Konstantin Dinev <[email protected]>
1 parent bc3adc7 commit fb8a813

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,13 +4110,33 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
41104110
}
41114111

41124112
/**
4113-
* Manually marks the `IgxGridComponent` for change detection.
4113+
* Triggers change detection for the `IgxGridComponent`.
4114+
* Calling markForCheck also triggers the grid pipes explicitly, resulting in all updates being processed.
4115+
* May degrade performance if used when not needed, or if misused:
4116+
* ```typescript
4117+
* // DON'Ts:
4118+
* // don't call markForCheck from inside a loop
4119+
* // don't call markForCheck when a primitive has changed
4120+
* grid.data.forEach(rec => {
4121+
* rec = newValue;
4122+
* grid.markForCheck();
4123+
* });
4124+
*
4125+
* // DOs
4126+
* // call markForCheck after updating a nested property
4127+
* grid.data.forEach(rec => {
4128+
* rec.nestedProp1.nestedProp2 = newValue;
4129+
* });
4130+
* grid.markForCheck();
4131+
* ```
4132+
*
41144133
* @example
41154134
* ```typescript
4116-
* this.grid1.markForCheck();
4135+
* grid.markForCheck();
41174136
* ```
41184137
*/
41194138
public markForCheck() {
4139+
this._pipeTrigger++;
41204140
this.cdr.detectChanges();
41214141
}
41224142

projects/igniteui-angular/src/lib/grids/hierarchical-grid/row-island.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class IgxRowIslandComponent extends IgxHierarchicalGridBaseDirective
9292
if (document.body.contains(grid.nativeElement)) {
9393
// Detect changes right away if the grid is visible
9494
grid.expandChildren = value;
95-
grid.markForCheck();
95+
grid.cdr.detectChanges();
9696
} else {
9797
// Else defer the detection on changes when the grid gets into view for performance.
9898
grid.updateOnRender = true;

projects/igniteui-angular/src/lib/grids/row-drag.directive.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
5858
}
5959
this.row.grid.dragRowID = this.row.rowID;
6060
this.row.grid.rowDragging = true;
61-
this.row.grid.markForCheck();
61+
this.row.grid.cdr.detectChanges();
6262

6363
this.subscription$ = fromEvent(this.row.grid.document.defaultView, 'keydown').subscribe((ev: KeyboardEvent) => {
6464
if (ev.key === KEYS.ESCAPE || ev.key === KEYS.ESCAPE_IE) {
@@ -96,7 +96,7 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
9696

9797
protected createGhost(pageX, pageY) {
9898
this.row.grid.endEdit(true);
99-
this.row.grid.markForCheck();
99+
this.row.grid.cdr.detectChanges();
100100
this.ghostContext = {
101101
$implicit: this.row.rowData,
102102
data: this.row.rowData,
@@ -141,7 +141,7 @@ export class IgxRowDragDirective extends IgxDragDirective implements OnDestroy {
141141
this.onTransitionEnd(null);
142142
this.row.grid.dragRowID = null;
143143
this.row.grid.rowDragging = false;
144-
this.row.grid.markForCheck();
144+
this.row.grid.cdr.detectChanges();
145145
this._unsubscribe();
146146
}
147147

0 commit comments

Comments
 (0)