Skip to content

Commit 3dae5ba

Browse files
authored
Merge pull request #12548 from IgniteUI/dkamburov/fix-12538
fix(grid): make the cell required in cell template context
2 parents e77f59e + a6a4d95 commit 3dae5ba

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { formatCurrency, formatDate, PlatformUtil } from '../core/utils';
2424
import { IgxGridSelectionService } from './selection/selection.service';
2525
import { HammerGesturesManager } from '../core/touch';
2626
import { GridSelectionMode } from './common/enums';
27-
import { CellType, ColumnType, GridType, IGX_GRID_BASE, RowType } from './common/grid.interface';
27+
import { CellType, ColumnType, GridType, IgxCellTemplateContext, IGX_GRID_BASE, RowType } from './common/grid.interface';
2828
import { getCurrencySymbol, getLocaleCurrencyCode } from '@angular/common';
2929
import { GridColumnDataType } from '../data-operations/data-util';
3030
import { IgxRowDirective } from './row.directive';
@@ -210,24 +210,25 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
210210
*
211211
* @memberof IgxGridCellComponent
212212
*/
213-
public get context(): any {
214-
const ctx = {
213+
public get context(): IgxCellTemplateContext {
214+
const getCellType = () => this.getCellType(true);
215+
const ctx: IgxCellTemplateContext = {
215216
$implicit: this.value,
216-
additionalTemplateContext: this.column.additionalTemplateContext
217+
additionalTemplateContext: this.column.additionalTemplateContext,
218+
get cell() {
219+
/* Turns the `cell` property from the template context object into lazy-evaluated one.
220+
* Otherwise on each detection cycle the cell template is recreating N cell instances where
221+
* N = number of visible cells in the grid, leading to massive performance degradation in large grids.
222+
*/
223+
return getCellType();
224+
}
217225
};
218226
if (this.editMode) {
219-
ctx['formControl'] = this.formControl;
227+
ctx.formControl = this.formControl;
220228
}
221229
if (this.isInvalid) {
222-
ctx['defaultErrorTemplate'] = this.defaultErrorTemplate;
230+
ctx.defaultErrorTemplate = this.defaultErrorTemplate;
223231
}
224-
/* Turns the `cell` property from the template context object into lazy-evaluated one.
225-
* Otherwise on each detection cycle the cell template is recreating N cell instances where
226-
* N = number of visible cells in the grid, leading to massive performance degradation in large grids.
227-
*/
228-
Object.defineProperty(ctx, 'cell', {
229-
get: () => this.getCellType(true)
230-
});
231232
return ctx;
232233
}
233234

projects/igniteui-angular/src/lib/grids/common/grid.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ export interface IgxCellTemplateContext {
775775
additionalTemplateContext: any,
776776
formControl?: FormControl<any>,
777777
defaultErrorTemplate?: TemplateRef<any>,
778-
cell?: CellType
778+
cell: CellType
779779
}
780780

781781
export interface IgxRowSelectorTemplateContext {

0 commit comments

Comments
 (0)