Skip to content

Commit e7f95cd

Browse files
authored
Merge pull request #9940 from IgniteUI/rkaraivanov/cell-template-performance
perf(grid): Cell template context
2 parents 6b2efdc + 90eb59b commit e7f95cd

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { ColumnType } from './common/column.interface';
2525
import { RowType } from './common/row.interface';
2626
import { GridSelectionMode } from './common/enums';
2727
import { GridType } from './common/grid.interface';
28-
import { getCurrencySymbol, getLocaleCurrencyCode} from '@angular/common';
28+
import { getCurrencySymbol, getLocaleCurrencyCode } from '@angular/common';
2929
import { GridColumnDataType } from '../data-operations/data-util';
3030
import { IgxRowDirective } from './row.directive';
3131
import { ISearchInfo } from './common/events';
@@ -165,11 +165,18 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
165165
* @memberof IgxGridCellComponent
166166
*/
167167
public get context(): any {
168-
return {
168+
const ctx = {
169169
$implicit: this.value,
170-
cell: this.getCellType(),
171-
additionalTemplateContext: this.column.additionalTemplateContext
170+
additionalTemplateContext: this.column.additionalTemplateContext,
172171
};
172+
/* Turns the `cell` property from the template context object into lazy-evaluated one.
173+
* Otherwise on each detection cycle the cell template is recreating N cell instances where
174+
* N = number of visible cells in the grid, leading to massive performance degradation in large grids.
175+
*/
176+
Object.defineProperty(ctx, 'cell', {
177+
get: () => this.getCellType()
178+
});
179+
return ctx;
173180
}
174181

175182
/**
@@ -804,7 +811,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
804811
cell = this.grid.crudService.createCell(this);
805812
}
806813
cell.editValue = val;
807-
const args = this.gridAPI.update_cell(cell);
814+
this.gridAPI.update_cell(cell);
808815
this.grid.crudService.endCellEdit();
809816
this.cdr.markForCheck();
810817
}
@@ -831,7 +838,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
831838
}
832839
return;
833840
}
834-
if(this.platformUtil.isFirefox) {
841+
if (this.platformUtil.isFirefox) {
835842
event.preventDefault();
836843
}
837844
this.selectionService.pointerDown(this.selectionNode, event.shiftKey, event.ctrlKey);

0 commit comments

Comments
 (0)