• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 16652945704

31 Jul 2025 03:14PM UTC coverage: 91.383%. First build
16652945704

Pull #16024

github

web-flow
Merge e46786e6b into a3f38e762
Pull Request #16024: Grid Cell merging

13567 of 15947 branches covered (85.08%)

199 of 219 new or added lines in 10 files covered. (90.87%)

27350 of 29929 relevant lines covered (91.38%)

35553.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.85
/projects/igniteui-angular/src/lib/grids/cell.component.ts
1
import { useAnimation } from '@angular/animations';
2
import {
3
    ChangeDetectionStrategy,
4
    ChangeDetectorRef,
5
    Component,
6
    ElementRef,
7
    HostBinding,
8
    HostListener,
9
    Input,
10
    TemplateRef,
11
    ViewChild,
12
    NgZone,
13
    OnInit,
14
    OnDestroy,
15
    OnChanges,
16
    SimpleChanges,
17
    Inject,
18
    ViewChildren,
19
    QueryList,
20
    AfterViewInit,
21
    booleanAttribute
22
} from '@angular/core';
23
import { formatPercent, NgClass, NgTemplateOutlet, DecimalPipe, PercentPipe, CurrencyPipe, DatePipe, getLocaleCurrencyCode, getCurrencySymbol } from '@angular/common';
24
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
25

26
import { first, takeUntil, takeWhile } from 'rxjs/operators';
27
import { Subject } from 'rxjs';
28

29
import { IgxTextHighlightDirective } from '../directives/text-highlight/text-highlight.directive';
30
import { formatCurrency, formatDate, PlatformUtil } from '../core/utils';
31
import { IgxGridSelectionService } from './selection/selection.service';
32
import { HammerGesturesManager } from '../core/touch';
33
import { GridSelectionMode } from './common/enums';
34
import { CellType, ColumnType, GridType, IgxCellTemplateContext, IGX_GRID_BASE, RowType } from './common/grid.interface';
35
import { GridColumnDataType } from '../data-operations/data-util';
36
import { IgxRowDirective } from './row.directive';
37
import { ISearchInfo } from './common/events';
38
import { IgxGridCell } from './grid-public-cell';
39
import { ISelectionNode } from './common/types';
40
import { AutoPositionStrategy, HorizontalAlignment, IgxOverlayService } from '../services/public_api';
41
import { IgxIconComponent } from '../icon/icon.component';
42
import { IgxGridCellImageAltPipe, IgxStringReplacePipe, IgxColumnFormatterPipe } from './common/pipes';
43
import { IgxTooltipDirective } from '../directives/tooltip/tooltip.directive';
44
import { IgxTooltipTargetDirective } from '../directives/tooltip/tooltip-target.directive';
45
import { IgxSuffixDirective } from '../directives/suffix/suffix.directive';
46
import { IgxPrefixDirective } from '../directives/prefix/prefix.directive';
47
import { IgxDateTimeEditorDirective } from '../directives/date-time-editor/date-time-editor.directive';
48
import { IgxTimePickerComponent } from '../time-picker/time-picker.component';
49
import { IgxDatePickerComponent } from '../date-picker/date-picker.component';
50
import { IgxCheckboxComponent } from '../checkbox/checkbox.component';
51
import { IgxTextSelectionDirective } from '../directives/text-selection/text-selection.directive';
52
import { IgxFocusDirective } from '../directives/focus/focus.directive';
53
import { IgxInputDirective } from '../directives/input/input.directive';
54
import { IgxInputGroupComponent } from '../input-group/input-group.component';
55
import { IgxChipComponent } from '../chips/chip.component';
56
import { fadeOut, scaleInCenter } from 'igniteui-angular/animations';
57

58
/**
59
 * Providing reference to `IgxGridCellComponent`:
60
 * ```typescript
61
 * @ViewChild('grid', { read: IgxGridComponent })
62
 *  public grid: IgxGridComponent;
63
 * ```
64
 * ```typescript
65
 *  let column = this.grid.columnList.first;
66
 * ```
67
 * ```typescript
68
 *  let cell = column.cells[0];
69
 * ```
70
 */
71
@Component({
72
    changeDetection: ChangeDetectionStrategy.OnPush,
73
    selector: 'igx-grid-cell',
74
    templateUrl: './cell.component.html',
75
    providers: [HammerGesturesManager],
76
    imports: [
77
        NgClass,
78
        NgTemplateOutlet,
79
        DecimalPipe,
80
        PercentPipe,
81
        CurrencyPipe,
82
        DatePipe,
83
        ReactiveFormsModule,
84
        IgxChipComponent,
85
        IgxTextHighlightDirective,
86
        IgxIconComponent,
87
        IgxInputGroupComponent,
88
        IgxInputDirective,
89
        IgxFocusDirective,
90
        IgxTextSelectionDirective,
91
        IgxCheckboxComponent,
92
        IgxDatePickerComponent,
93
        IgxTimePickerComponent,
94
        IgxDateTimeEditorDirective,
95
        IgxPrefixDirective,
96
        IgxSuffixDirective,
97
        IgxTooltipTargetDirective,
98
        IgxTooltipDirective,
99
        IgxGridCellImageAltPipe,
100
        IgxStringReplacePipe,
101
        IgxColumnFormatterPipe
102
    ]
103
})
104
export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellType, AfterViewInit {
3✔
105
    private _destroy$ = new Subject<void>();
154,626✔
106
    /**
107
     * @hidden
108
     * @internal
109
     */
110
    @HostBinding('class.igx-grid__td--new')
111
    public get isEmptyAddRowCell() {
112
        return this.intRow.addRowUI && (this.value === undefined || this.value === null);
1,224,161✔
113
    }
114

115
    /**
116
     * @hidden
117
     * @internal
118
     */
119
    @ViewChildren('error', { read: IgxTooltipDirective })
120
    public errorTooltip: QueryList<IgxTooltipDirective>;
121

122
    /**
123
     * @hidden
124
     * @internal
125
     */
126
    @ViewChild('errorIcon', { read: IgxIconComponent, static: false })
127
    public errorIcon: IgxIconComponent;
128

129
    /**
130
     * Gets the default error template.
131
     * @hidden @internal
132
     */
133
    @ViewChild('defaultError', { read: TemplateRef, static: true })
134
    public defaultErrorTemplate: TemplateRef<any>;
135

136
    /**
137
     * Gets the column of the cell.
138
     * ```typescript
139
     *  let cellColumn = this.cell.column;
140
     * ```
141
     *
142
     * @memberof IgxGridCellComponent
143
     */
144
    @Input()
145
    public column: ColumnType;
146

147
    /**
148
     * @hidden
149
     * @internal
150
     */
151
    @Input()
152
    public isPlaceholder: boolean;
153

154
    /**
155
        Gets whether this cell is a merged cell.
156
     */
157
    @Input()
158
    public isMerged: boolean;
159

160
    /**
161
     * @hidden
162
     * @internal
163
     */
164
    protected get formGroup(): FormGroup {
165
        return this.grid.validation.getFormGroup(this.intRow.key);
5,950,550✔
166
    }
167

168
    /**
169
     * @hidden
170
     * @internal
171
     */
172
    @Input()
173
    public intRow: IgxRowDirective;
174

175
    /**
176
     * Gets the row of the cell.
177
     * ```typescript
178
     * let cellRow = this.cell.row;
179
     * ```
180
     *
181
     * @memberof IgxGridCellComponent
182
     */
183
    @Input()
184
    public get row(): RowType {
185
        return this.grid.createRow(this.intRow.index);
8,255✔
186
    }
187

188
    /**
189
     * Gets the data of the row of the cell.
190
     * ```typescript
191
     * let rowData = this.cell.rowData;
192
     * ```
193
     *
194
     * @memberof IgxGridCellComponent
195
     */
196
    @Input()
197
    public rowData: any;
198

199
    /**
200
     * @hidden
201
     * @internal
202
     */
203
    @Input()
204
    public columnData: any;
205

206
    /**
207
     * Sets/gets the template of the cell.
208
     * ```html
209
     * <ng-template #cellTemplate igxCell let-value>
210
     *   <div style="font-style: oblique; color:blueviolet; background:red">
211
     *       <span>{{value}}</span>
212
     *   </div>
213
     * </ng-template>
214
     * ```
215
     * ```typescript
216
     * @ViewChild('cellTemplate',{read: TemplateRef})
217
     * cellTemplate: TemplateRef<any>;
218
     * ```
219
     * ```typescript
220
     * this.cell.cellTemplate = this.cellTemplate;
221
     * ```
222
     * ```typescript
223
     * let template =  this.cell.cellTemplate;
224
     * ```
225
     *
226
     * @memberof IgxGridCellComponent
227
     */
228
    @Input()
229
    public cellTemplate: TemplateRef<any>;
230

231
    @Input()
232
    public cellValidationErrorTemplate: TemplateRef<any>;
233

234
    @Input()
235
    public pinnedIndicator: TemplateRef<any>;
236

237
    /**
238
     * Sets/gets the cell value.
239
     * ```typescript
240
     * this.cell.value = "Cell Value";
241
     * ```
242
     * ```typescript
243
     * let cellValue = this.cell.value;
244
     * ```
245
     *
246
     * @memberof IgxGridCellComponent
247
     */
248
    @Input()
249
    public value: any;
250

251
    /**
252
     * Gets the cell formatter.
253
     * ```typescript
254
     * let cellForamatter = this.cell.formatter;
255
     * ```
256
     *
257
     * @memberof IgxGridCellComponent
258
     */
259
    @Input()
260
    public formatter: (value: any, rowData?: any, columnData?: any) => any;
261

262
    /**
263
     * Gets the cell template context object.
264
     * ```typescript
265
     *  let context = this.cell.context();
266
     * ```
267
     *
268
     * @memberof IgxGridCellComponent
269
     */
270
    public get context(): IgxCellTemplateContext {
271
        const getCellType = () => this.getCellType(true);
655,519✔
272
        const ctx: IgxCellTemplateContext = {
655,519✔
273
            $implicit: this.value,
274
            additionalTemplateContext: this.column.additionalTemplateContext,
275
            get cell() {
276
                /* Turns the `cell` property from the template context object into lazy-evaluated one.
277
                 * Otherwise on each detection cycle the cell template is recreating N cell instances where
278
                 * N = number of visible cells in the grid, leading to massive performance degradation in large grids.
279
                 */
280
                return getCellType();
2,025✔
281
            }
282
        };
283
        if (this.editMode) {
655,519✔
284
            ctx.formControl = this.formControl;
2,493✔
285
        }
286
        if (this.isInvalid) {
655,519✔
287
            ctx.defaultErrorTemplate = this.defaultErrorTemplate;
429✔
288
        }
289
        return ctx;
655,519✔
290
    }
291

292
    /**
293
     * Gets the cell template.
294
     * ```typescript
295
     * let template = this.cell.template;
296
     * ```
297
     *
298
     * @memberof IgxGridCellComponent
299
     */
300
    public get template(): TemplateRef<any> {
301
        if (this.isPlaceholder) {
327,712✔
302
            return this.emptyCellTemplate;
198✔
303
        }
304
        if (this.editMode && this.formGroup) {
327,514✔
305
            const inlineEditorTemplate = this.column.inlineEditorTemplate;
1,245✔
306
            return inlineEditorTemplate ? inlineEditorTemplate : this.inlineEditorTemplate;
1,245✔
307
        }
308
        if (this.cellTemplate) {
326,269✔
309
            return this.cellTemplate;
763✔
310
        }
311
        if (this.grid.rowEditable && this.intRow.addRowUI) {
325,506✔
312
            return this.addRowCellTemplate;
1,918✔
313
        }
314
        return this.defaultCellTemplate;
323,588✔
315
    }
316

317
    /**
318
     * Gets the pinned indicator template.
319
     * ```typescript
320
     * let template = this.cell.pinnedIndicatorTemplate;
321
     * ```
322
     *
323
     * @memberof IgxGridCellComponent
324
     */
325
    public get pinnedIndicatorTemplate() {
326
        if (this.pinnedIndicator) {
327,664!
327
            return this.pinnedIndicator;
×
328
        }
329
        return this.defaultPinnedIndicator;
327,664✔
330
    }
331

332
    /**
333
     * Gets the `id` of the grid in which the cell is stored.
334
     * ```typescript
335
     * let gridId = this.cell.gridID;
336
     * ```
337
     *
338
     * @memberof IgxGridCellComponent
339
     */
340
    public get gridID(): any {
341
        return this.intRow.gridID;
1,529,251✔
342
    }
343

344

345
    /**
346
     * Gets the `index` of the row where the cell is stored.
347
     * ```typescript
348
     * let rowIndex = this.cell.rowIndex;
349
     * ```
350
     *
351
     * @memberof IgxGridCellComponent
352
     */
353
    @HostBinding('attr.data-rowIndex')
354
    public get rowIndex(): number {
355
        return this.intRow.index;
4,894,604✔
356
    }
357

358
    /**
359
     * Gets the `index` of the cell column.
360
     * ```typescript
361
     * let columnIndex = this.cell.columnIndex;
362
     * ```
363
     *
364
     * @memberof IgxGridCellComponent
365
     */
366
    public get columnIndex(): number {
367
        return this.column.index;
17,843✔
368
    }
369

370
    /**
371
     * Returns the column visible index.
372
     * ```typescript
373
     * let visibleColumnIndex = this.cell.visibleColumnIndex;
374
     * ```
375
     *
376
     * @memberof IgxGridCellComponent
377
     */
378
    @HostBinding('attr.data-visibleIndex')
379
    @Input()
380
    public get visibleColumnIndex() {
381
        return this.column.columnLayoutChild ? this.column.visibleIndex : this._vIndex;
4,897,281✔
382
    }
383

384
    public set visibleColumnIndex(val) {
385
        this._vIndex = val;
161,166✔
386
    }
387

388
    /**
389
     * Gets the ID of the cell.
390
     * ```typescript
391
     * let cellID = this.cell.cellID;
392
     * ```
393
     *
394
     * @memberof IgxGridCellComponent
395
     */
396
    public get cellID() {
397
        const primaryKey = this.grid.primaryKey;
462✔
398
        const rowID = primaryKey ? this.rowData[primaryKey] : this.rowData;
462✔
399
        return { rowID, columnID: this.columnIndex, rowIndex: this.rowIndex };
462✔
400
    }
401

402
    @HostBinding('attr.id')
403
    public get attrCellID() {
404
        return `${this.intRow.gridID}_${this.rowIndex}_${this.visibleColumnIndex}`;
1,222,290✔
405
    }
406

407
    @HostBinding('attr.title')
408
    public get title() {
409
        if (this.editMode || this.cellTemplate || this.errorShowing) {
1,222,303✔
410
            return '';
5,437✔
411
        }
412

413
        if (this.formatter) {
1,216,866✔
414
            return this.formatter(this.value, this.rowData, this.columnData);
22,032✔
415
        }
416

417
        const args = this.column.pipeArgs;
1,194,834✔
418
        const locale = this.grid.locale;
1,194,834✔
419

420
        switch (this.column.dataType) {
1,194,834✔
421
            case GridColumnDataType.Percent:
422
                return formatPercent(this.value, locale, args.digitsInfo);
427✔
423
            case GridColumnDataType.Currency:
424
                return formatCurrency(this.value, this.currencyCode, args.display, args.digitsInfo, locale);
20,316✔
425
            case GridColumnDataType.Date:
426
            case GridColumnDataType.DateTime:
427
            case GridColumnDataType.Time:
428
                return formatDate(this.value, args.format, locale, args.timezone);
172,051✔
429
        }
430
        return this.value;
1,002,040✔
431
    }
432

433
    @HostBinding('class.igx-grid__td--bool-true')
434
    public get booleanClass() {
435
        return this.column.dataType === 'boolean' && this.value;
1,222,290✔
436
    }
437

438
    /**
439
     * Returns a reference to the nativeElement of the cell.
440
     * ```typescript
441
     * let cellNativeElement = this.cell.nativeElement;
442
     * ```
443
     *
444
     * @memberof IgxGridCellComponent
445
     */
446
    public get nativeElement(): HTMLElement {
447
        return this.element.nativeElement;
1,292,244✔
448
    }
449

450
    /**
451
     * @hidden
452
     * @internal
453
     */
454
    @Input()
455
    public get cellSelectionMode() {
456
        return this._cellSelection;
310,296✔
457
    }
458

459
    public set cellSelectionMode(value) {
460
        if (this._cellSelection === value) {
154,994✔
461
            return;
154,022✔
462
        }
463
        this.zone.runOutsideAngular(() => {
972✔
464
            if (value === GridSelectionMode.multiple) {
972✔
465
                this.addPointerListeners(value);
60✔
466
            } else {
467
                this.removePointerListeners(this._cellSelection);
912✔
468
            }
469
        });
470
        this._cellSelection = value;
972✔
471
    }
472

473
    /**
474
     * @hidden
475
     * @internal
476
     */
477
    @Input()
478
    public set lastSearchInfo(value: ISearchInfo) {
479
        this._lastSearchInfo = value;
160,151✔
480
        this.highlightText(this._lastSearchInfo.searchText, this._lastSearchInfo.caseSensitive, this._lastSearchInfo.exactMatch);
160,151✔
481
    }
482

483
    /**
484
     * @hidden
485
     * @internal
486
     */
487
    @Input()
488
    @HostBinding('class.igx-grid__td--pinned-last')
489
    public lastPinned = false;
154,626✔
490

491
    /**
492
     * @hidden
493
     * @internal
494
     */
495
    @Input()
496
    @HostBinding('class.igx-grid__td--pinned-first')
497
    public firstPinned = false;
154,626✔
498

499
    /**
500
     * Returns whether the cell is in edit mode.
501
     */
502
    @Input({ transform: booleanAttribute })
503
    @HostBinding('class.igx-grid__td--editing')
504
    public editMode = false;
154,626✔
505

506
    /**
507
     * Sets/get the `role` property of the cell.
508
     * Default value is `"gridcell"`.
509
     * ```typescript
510
     * this.cell.role = 'grid-cell';
511
     * ```
512
     * ```typescript
513
     * let cellRole = this.cell.role;
514
     * ```
515
     *
516
     * @memberof IgxGridCellComponent
517
     */
518
    @HostBinding('attr.role')
519
    public role = 'gridcell';
154,626✔
520

521
    /**
522
     * Gets whether the cell is editable.
523
     * ```typescript
524
     * let isCellReadonly = this.cell.readonly;
525
     * ```
526
     *
527
     * @memberof IgxGridCellComponent
528
     */
529
    @HostBinding('attr.aria-readonly')
530
    public get readonly(): boolean {
531
        return !this.editable;
1,222,291✔
532
    }
533

534
    /** @hidden @internal */
535
    @HostBinding('attr.aria-describedby')
536
    public get ariaDescribeBy() {
537
        let describeBy = (this.gridID + '_' + this.column.field).replace('.', '_');
1,223,389✔
538
        if (this.isInvalid) {
1,223,389✔
539
            describeBy += ' ' + this.ariaErrorMessage;
110✔
540
        }
541
        return describeBy;
1,223,389✔
542
    }
543

544
    /** @hidden @internal */
545
    public get ariaErrorMessage() {
546
        return this.grid.id + '_' + this.column.field + '_' + this.intRow.index + '_error';
253✔
547
    }
548

549
    /**
550
     * @hidden
551
     * @internal
552
     */
553
    @HostBinding('class.igx-grid__td--invalid')
554
    @HostBinding('attr.aria-invalid')
555
    public get isInvalid() {
556
        if (this.formGroup) {
4,653,325✔
557
            const isInvalid = this.grid.validation?.isFieldInvalid(this.formGroup, this.column?.field);
61,339✔
558
            return !this.intRow.deleted && isInvalid;
61,339✔
559
        }
560
        return false;
4,591,986✔
561
    }
562

563
    /**
564
     * @hidden
565
     * @internal
566
     */
567
    @HostBinding('class.igx-grid__td--valid')
568
    public get isValidAfterEdit() {
569
        if (this.formGroup) {
1,222,290✔
570
            const isValidAfterEdit = this.grid.validation?.isFieldValidAfterEdit(this.formGroup, this.column?.field);
11,126✔
571
            return this.editMode && isValidAfterEdit;
11,126✔
572
        }
573
        return false;
1,211,164✔
574
    }
575

576
    /**
577
     * Gets the formControl responsible for value changes and validation for this cell.
578
     */
579
    protected get formControl(): FormControl {
580
        return this.grid.validation.getFormControl(this.intRow.key, this.column.field) as FormControl;
54,617✔
581
    }
582

583
    public get gridRowSpan(): number {
584
        return this.column.gridRowSpan;
198✔
585
    }
586

587
    public get gridColumnSpan(): number {
588
        return this.column.gridColumnSpan;
198✔
589
    }
590

591
    public get rowEnd(): number {
592
        return this.column.rowEnd;
×
593
    }
594

595
    public get colEnd(): number {
596
        return this.column.colEnd;
×
597
    }
598

599
    public get rowStart(): number {
600
        return this.column.rowStart;
×
601
    }
602

603
    public get colStart(): number {
604
        return this.column.colStart;
×
605
    }
606

607
    /**
608
     * Gets the width of the cell.
609
     * ```typescript
610
     * let cellWidth = this.cell.width;
611
     * ```
612
     *
613
     * @memberof IgxGridCellComponent
614
     */
615
    @Input()
616
    public width = '';
154,626✔
617

618
    /**
619
     * @hidden
620
     */
621
    @Input()
622
    @HostBinding('class.igx-grid__td--active')
623
    public active = false;
154,626✔
624

625
    @HostBinding('attr.aria-selected')
626
    public get ariaSelected() {
627
        return this.selected || this.column.selected || this.intRow.selected;
1,222,290✔
628
    }
629

630
    /**
631
     * Gets whether the cell is selected.
632
     * ```typescript
633
     * let isSelected = this.cell.selected;
634
     * ```
635
     *
636
     * @memberof IgxGridCellComponent
637
     */
638
    @HostBinding('class.igx-grid__td--selected')
639
    public get selected() {
640
        return this.selectionService.selected(this.selectionNode);
2,446,665✔
641
    }
642

643
    /**
644
     * Selects/deselects the cell.
645
     * ```typescript
646
     * this.cell.selected = true.
647
     * ```
648
     *
649
     * @memberof IgxGridCellComponent
650
     */
651
    public set selected(val: boolean) {
652
        const node = this.selectionNode;
1✔
653
        if (val) {
1!
654
            this.selectionService.add(node);
1✔
655
        } else {
656
            this.selectionService.remove(node);
×
657
        }
658
        this.grid.notifyChanges();
1✔
659
    }
660

661
    /**
662
     * Gets whether the cell column is selected.
663
     * ```typescript
664
     * let isCellColumnSelected = this.cell.columnSelected;
665
     * ```
666
     *
667
     * @memberof IgxGridCellComponent
668
     */
669
    @HostBinding('class.igx-grid__td--column-selected')
670
    public get columnSelected() {
671
        return this.selectionService.isColumnSelected(this.column.field);
1,222,290✔
672
    }
673

674
    /**
675
     * Sets the current edit value while a cell is in edit mode.
676
     * Only for cell editing mode.
677
     * ```typescript
678
     * this.cell.editValue = value;
679
     * ```
680
     *
681
     * @memberof IgxGridCellComponent
682
     */
683
    public set editValue(value) {
684
        if (this.grid.crudService.cellInEditMode) {
44✔
685
            this.grid.crudService.cell.editValue = value;
44✔
686
        }
687
    }
688

689
    /**
690
     * Gets the current edit value while a cell is in edit mode.
691
     * Only for cell editing mode.
692
     * ```typescript
693
     * let editValue = this.cell.editValue;
694
     * ```
695
     *
696
     * @memberof IgxGridCellComponent
697
     */
698
    public get editValue() {
699
        if (this.grid.crudService.cellInEditMode) {
163✔
700
            return this.grid.crudService.cell.editValue;
163✔
701
        }
702
    }
703

704
    /**
705
     * Returns whether the cell is editable.
706
     */
707
    public get editable(): boolean {
708
        return this.column.editable && !this.intRow.disabled;
1,223,569✔
709
    }
710

711
    /**
712
     * @hidden
713
     */
714
    @Input()
715
    @HostBinding('class.igx-grid__td--row-pinned-first')
716
    public displayPinnedChip = false;
154,626✔
717

718
    @HostBinding('style.min-height.px')
719
    protected get minHeight() {
720
        if ((this.grid as any).isCustomSetRowHeight) {
1,222,290✔
721
            return this.grid.renderedRowHeight;
464✔
722
        }
723
    }
724

725
    @ViewChild('defaultCell', { read: TemplateRef, static: true })
726
    protected defaultCellTemplate: TemplateRef<any>;
727

728
    @ViewChild('emptyCell', { read: TemplateRef, static: true })
729
    protected emptyCellTemplate: TemplateRef<any>;
730

731
    @ViewChild('defaultPinnedIndicator', { read: TemplateRef, static: true })
732
    protected defaultPinnedIndicator: TemplateRef<any>;
733

734
    @ViewChild('inlineEditor', { read: TemplateRef, static: true })
735
    protected inlineEditorTemplate: TemplateRef<any>;
736

737
    @ViewChild('addRowCell', { read: TemplateRef, static: true })
738
    protected addRowCellTemplate: TemplateRef<any>;
739

740
    @ViewChild(IgxTextHighlightDirective, { read: IgxTextHighlightDirective })
741
    protected set highlight(value: IgxTextHighlightDirective) {
742
        this._highlight = value;
156,775✔
743

744
        if (this._highlight && this.grid.lastSearchInfo.searchText) {
156,775✔
745
            this._highlight.highlight(this.grid.lastSearchInfo.searchText,
400✔
746
                this.grid.lastSearchInfo.caseSensitive,
747
                this.grid.lastSearchInfo.exactMatch);
748
            this._highlight.activateIfNecessary();
400✔
749
        }
750
    }
751

752
    protected get highlight() {
753
        return this._highlight;
356,499✔
754
    }
755

756
    protected get selectionNode(): ISelectionNode {
757
        return {
2,448,570✔
758
            row: this.rowIndex,
759
            column: this.column.columnLayoutChild ? this.column.parent.visibleIndex : this.visibleColumnIndex,
2,448,570✔
760
            layout: this.column.columnLayoutChild ? {
2,448,570✔
761
                rowStart: this.column.rowStart,
762
                colStart: this.column.colStart,
763
                rowEnd: this.column.rowEnd,
764
                colEnd: this.column.colEnd,
765
                columnVisibleIndex: this.visibleColumnIndex
766
            } : null
767
        };
768
    }
769

770
    /**
771
     * Sets/gets the highlight class of the cell.
772
     * Default value is `"igx-highlight"`.
773
     * ```typescript
774
     * let highlightClass = this.cell.highlightClass;
775
     * ```
776
     * ```typescript
777
     * this.cell.highlightClass = 'igx-cell-highlight';
778
     * ```
779
     *
780
     * @memberof IgxGridCellComponent
781
     */
782
    public highlightClass = 'igx-highlight';
154,626✔
783

784
    /**
785
     * Sets/gets the active highlight class class of the cell.
786
     * Default value is `"igx-highlight__active"`.
787
     * ```typescript
788
     * let activeHighlightClass = this.cell.activeHighlightClass;
789
     * ```
790
     * ```typescript
791
     * this.cell.activeHighlightClass = 'igx-cell-highlight_active';
792
     * ```
793
     *
794
     * @memberof IgxGridCellComponent
795
     */
796
    public activeHighlightClass = 'igx-highlight__active';
154,626✔
797

798
    /** @hidden @internal */
799
    public get step(): number {
800
        const digitsInfo = this.column.pipeArgs.digitsInfo;
218✔
801
        if (!digitsInfo) {
218!
802
            return 1;
×
803
        }
804
        const step = +digitsInfo.substr(digitsInfo.indexOf('.') + 1, 1);
218✔
805
        return 1 / (Math.pow(10, step));
218✔
806
    }
807

808
    /** @hidden @internal */
809
    public get currencyCode(): string {
810
        return this.column.pipeArgs.currencyCode ?
57,180✔
811
            this.column.pipeArgs.currencyCode : getLocaleCurrencyCode(this.grid.locale);
812
    }
813

814
    /** @hidden @internal */
815
    public get currencyCodeSymbol(): string {
816
        return getCurrencySymbol(this.currencyCode, 'wide', this.grid.locale);
4✔
817
    }
818

819
    protected _lastSearchInfo: ISearchInfo;
820
    private _highlight: IgxTextHighlightDirective;
821
    private _cellSelection: GridSelectionMode = GridSelectionMode.multiple;
154,626✔
822
    private _vIndex = -1;
154,626✔
823

824
    constructor(
825
        protected selectionService: IgxGridSelectionService,
154,626✔
826
        @Inject(IGX_GRID_BASE) public grid: GridType,
154,626✔
827
        @Inject(IgxOverlayService) protected overlayService: IgxOverlayService,
154,626✔
828
        public cdr: ChangeDetectorRef,
154,626✔
829
        private element: ElementRef<HTMLElement>,
154,626✔
830
        protected zone: NgZone,
154,626✔
831
        private touchManager: HammerGesturesManager,
154,626✔
832
        protected platformUtil: PlatformUtil
154,626✔
833
    ) { }
834

835
    /**
836
     * @hidden
837
     * @internal
838
     */
839
    @HostListener('dblclick', ['$event'])
840
    public onDoubleClick = (event: MouseEvent) => {
154,626✔
841
        if (event.type === 'doubletap') {
153✔
842
            // prevent double-tap to zoom on iOS
843
            event.preventDefault();
1✔
844
        }
845
        if (this.editable && !this.editMode && !this.intRow.deleted && !this.grid.crudService.rowEditingBlocked) {
153✔
846
            this.grid.crudService.enterEditMode(this, event as Event);
147✔
847
        }
848

849
        this.grid.doubleClick.emit({
153✔
850
            cell: this.getCellType(),
851
            event
852
        });
853
    };
854

855
    /**
856
     * @hidden
857
     * @internal
858
     */
859
    @HostListener('click', ['$event'])
860
    public onClick(event: MouseEvent) {
861
        this.grid.cellClick.emit({
265✔
862
            cell: this.getCellType(),
863
            event
864
        });
865
    }
866

867
    /**
868
     * @hidden
869
     * @internal
870
     */
871
    public ngOnInit() {
872
        this.zone.runOutsideAngular(() => {
154,626✔
873
            this.nativeElement.addEventListener('pointerdown', this.pointerdown);
154,626✔
874
            this.addPointerListeners(this.cellSelectionMode);
154,626✔
875
        });
876
        if (this.platformUtil.isIOS) {
154,626✔
877
            this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
40✔
878
                cssProps: {} /* don't disable user-select, etc */
879
            });
880
        }
881

882
    }
883

884
    public ngAfterViewInit() {
885
        this.errorTooltip.changes.pipe(takeUntil(this._destroy$)).subscribe(() => {
154,626✔
886
            if (this.errorTooltip.length > 0 && this.active) {
44✔
887
                // error ocurred
888
                this.cdr.detectChanges();
25✔
889
                this.openErrorTooltip();
25✔
890
            }
891
        });
892
    }
893

894
    /**
895
     * @hidden
896
     * @internal
897
     */
898
    public errorShowing = false;
154,626✔
899

900
    private openErrorTooltip() {
901
        const tooltip = this.errorTooltip.first;
26✔
902
        tooltip.open(
26✔
903
            {
904
                target: this.errorIcon.el.nativeElement,
905
                closeOnOutsideClick: true,
906
                excludeFromOutsideClick: [this.nativeElement],
907
                closeOnEscape: false,
908
                outlet: this.grid.outlet,
909
                modal: false,
910
                positionStrategy: new AutoPositionStrategy({
911
                    horizontalStartPoint: HorizontalAlignment.Center,
912
                    horizontalDirection: HorizontalAlignment.Center,
913
                    openAnimation: useAnimation(scaleInCenter, { params: { duration: '150ms' } }),
914
                    closeAnimation: useAnimation(fadeOut, { params: { duration: '75ms' } })
915
                })
916
            }
917
        );
918
    }
919

920
    /**
921
     * @hidden
922
     * @internal
923
     */
924
    public ngOnDestroy() {
925
        this.zone.runOutsideAngular(() => {
153,281✔
926
            this.nativeElement.removeEventListener('pointerdown', this.pointerdown);
153,281✔
927
            this.removePointerListeners(this.cellSelectionMode);
153,281✔
928
        });
929
        this.touchManager.destroy();
153,281✔
930
        this._destroy$.next();
153,281✔
931
        this._destroy$.complete();
153,281✔
932
    }
933

934
    /**
935
     * @hidden
936
     * @internal
937
     */
938
    public ngOnChanges(changes: SimpleChanges): void {
939
        if (changes.editMode && changes.editMode.currentValue && this.formControl) {
293,845✔
940
            // ensure when values change, form control is forced to be marked as touche.
941
            this.formControl.valueChanges.pipe(takeWhile(() => this.editMode)).subscribe(() => this.formControl.markAsTouched());
402✔
942
            // while in edit mode subscribe to value changes on the current form control and set to editValue
943
            this.formControl.statusChanges.pipe(takeWhile(() => this.editMode)).subscribe(status => {
402✔
944
                if (status === 'INVALID' && this.errorTooltip.length > 0) {
192!
945
                    this.cdr.detectChanges();
×
946
                    const tooltip = this.errorTooltip.first;
×
947
                    this.resizeAndRepositionOverlayById(tooltip.overlayId, this.errorTooltip.first.element.offsetWidth);
×
948
                }
949
            });
950
        }
951
        if (changes.value && !changes.value.firstChange) {
293,845✔
952
            if (this.highlight) {
47,949✔
953
                this.highlight.lastSearchInfo.searchText = this.grid.lastSearchInfo.searchText;
45,525✔
954
                this.highlight.lastSearchInfo.caseSensitive = this.grid.lastSearchInfo.caseSensitive;
45,525✔
955
                this.highlight.lastSearchInfo.exactMatch = this.grid.lastSearchInfo.exactMatch;
45,525✔
956
            }
957
            const isInEdit = this.grid.rowEditable ? this.row.inEditMode : this.editMode;
47,949✔
958
            if (this.formControl && this.formControl.value !== changes.value.currentValue && !isInEdit) {
47,949✔
959
                this.formControl.setValue(changes.value.currentValue);
131✔
960
            }
961
        }
962
    }
963

964

965

966
    /**
967
     * @hidden @internal
968
     */
969
    private resizeAndRepositionOverlayById(overlayId: string, newSize: number) {
970
        const overlay = this.overlayService.getOverlayById(overlayId);
×
971
        if (!overlay) return;
×
972
        overlay.initialSize.width = newSize;
×
973
        overlay.elementRef.nativeElement.parentElement.style.width = newSize + 'px';
×
974
        this.overlayService.reposition(overlayId);
×
975
    }
976

977
    /**
978
     * Starts/ends edit mode for the cell.
979
     *
980
     * ```typescript
981
     * cell.setEditMode(true);
982
     * ```
983
     */
984
    public setEditMode(value: boolean): void {
985
        if (this.intRow.deleted) {
30!
986
            return;
×
987
        }
988
        if (this.editable && value) {
30✔
989
            if (this.grid.crudService.cellInEditMode) {
26✔
990
                this.grid.gridAPI.update_cell(this.grid.crudService.cell);
5✔
991
                this.grid.crudService.endCellEdit();
5✔
992
            }
993
            this.grid.crudService.enterEditMode(this);
26✔
994
        } else {
995
            this.grid.crudService.endCellEdit();
4✔
996
        }
997
        this.grid.notifyChanges();
30✔
998
    }
999

1000
    /**
1001
     * Sets new value to the cell.
1002
     * ```typescript
1003
     * this.cell.update('New Value');
1004
     * ```
1005
     *
1006
     * @memberof IgxGridCellComponent
1007
     */
1008
    // TODO: Refactor
1009
    public update(val: any) {
1010
        if (this.intRow.deleted) {
34!
1011
            return;
×
1012
        }
1013

1014
        let cell = this.grid.crudService.cell;
34✔
1015
        if (!cell) {
34✔
1016
            cell = this.grid.crudService.createCell(this);
14✔
1017
        }
1018
        cell.editValue = val;
34✔
1019
        this.grid.gridAPI.update_cell(cell);
34✔
1020
        this.grid.crudService.endCellEdit();
34✔
1021
        this.cdr.markForCheck();
34✔
1022
    }
1023

1024
    /**
1025
     *
1026
     * @hidden
1027
     * @internal
1028
     */
1029
    public pointerdown = (event: PointerEvent) => {
154,626✔
1030

1031
        if (this.isMerged) {
433✔
1032
            // need an approximation of where in the cell the user clicked to get actual index to be activated.
1033
            const scrollOffset = this.grid.verticalScrollContainer.scrollPosition + (event.y - this.grid.tbody.nativeElement.getBoundingClientRect().y);
5✔
1034
            const targetRowIndex = this.grid.verticalScrollContainer.getIndexAtScroll(scrollOffset);
5✔
1035
            if (targetRowIndex != this.rowIndex) {
5!
NEW
1036
                const row = this.grid.rowList.toArray().find(x => x.index === targetRowIndex);
×
NEW
1037
                const actualTarget = row.cells.find(x => x.column === this.column);
×
NEW
1038
                actualTarget.pointerdown(event);
×
NEW
1039
                return;
×
1040
            }
1041
        }
1042

1043
        if (this.cellSelectionMode !== GridSelectionMode.multiple) {
433✔
1044
            this.activate(event);
23✔
1045
            return;
23✔
1046
        }
1047
        if (!this.platformUtil.isLeftClick(event)) {
410✔
1048
            event.preventDefault();
4✔
1049
            this.grid.navigation.setActiveNode({ rowIndex: this.rowIndex, colIndex: this.visibleColumnIndex });
4✔
1050
            this.selectionService.addKeyboardRange();
4✔
1051
            this.selectionService.initKeyboardState();
4✔
1052
            this.selectionService.primaryButton = false;
4✔
1053
            // Ensure RMB Click on edited cell does not end cell editing
1054
            if (!this.selected) {
4✔
1055
                this.grid.crudService.updateCell(true, event);
2✔
1056
            }
1057
            return;
4✔
1058
        } else {
1059
            this.selectionService.primaryButton = true;
406✔
1060
        }
1061
        this.selectionService.pointerDown(this.selectionNode, event.shiftKey, event.ctrlKey);
406✔
1062
        this.activate(event);
406✔
1063
    };
1064

1065
    /**
1066
     *
1067
     * @hidden
1068
     * @internal
1069
     */
1070
    public pointerenter = (event: PointerEvent) => {
154,626✔
1071
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
119✔
1072
        if (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID || this.grid.navigation.activeNode.gridID !== this.gridID)) {
119✔
1073
            return;
3✔
1074
        }
1075
        const dragMode = this.selectionService.pointerEnter(this.selectionNode, event);
116✔
1076
        if (dragMode) {
116✔
1077
            this.grid.cdr.detectChanges();
115✔
1078
        }
1079
    };
1080

1081
    /**
1082
     * @hidden
1083
     * @internal
1084
     */
1085
    public focusout = () => {
154,626✔
1086
        this.closeErrorTooltip();
49✔
1087
    }
1088

1089
    private closeErrorTooltip() {
1090
        const tooltip = this.errorTooltip.first;
49✔
1091
        if (tooltip) {
49!
1092
            tooltip.close();
×
1093
        }
1094
    }
1095

1096
    /**
1097
     * @hidden
1098
     * @internal
1099
     */
1100
    public pointerup = (event: PointerEvent) => {
154,626✔
1101
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
407✔
1102
        if (!this.platformUtil.isLeftClick(event) || (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID ||
407✔
1103
            this.grid.navigation.activeNode.gridID !== this.gridID))) {
1104
            return;
4✔
1105
        }
1106
        if (this.selectionService.pointerUp(this.selectionNode, this.grid.rangeSelected)) {
403✔
1107
            this.grid.cdr.detectChanges();
50✔
1108
        }
1109
    };
1110

1111
    /**
1112
     * @hidden
1113
     * @internal
1114
     */
1115
    public activate(event: FocusEvent | KeyboardEvent) {
1116
        const node = this.selectionNode;
979✔
1117
        let shouldEmitSelection = !this.selectionService.isActiveNode(node);
979✔
1118

1119
        if (this.selectionService.primaryButton) {
979!
1120
            const currentActive = this.selectionService.activeElement;
979✔
1121
            if (this.cellSelectionMode === GridSelectionMode.single && (event as any)?.ctrlKey && this.selected) {
979✔
1122
                this.selectionService.activeElement = null;
1✔
1123
                shouldEmitSelection = true;
1✔
1124
            } else {
1125
                this.selectionService.activeElement = node;
978✔
1126
            }
1127
            const cancel = this._updateCRUDStatus(event);
979✔
1128
            if (cancel) {
979✔
1129
                this.selectionService.activeElement = currentActive;
2✔
1130
                return;
2✔
1131
            }
1132

1133
            const activeElement = this.selectionService.activeElement;
977✔
1134
            const row = activeElement ? this.grid.gridAPI.get_row_by_index(activeElement.row) : null;
977✔
1135
            if (this.grid.crudService.rowEditingBlocked && row && this.intRow.key !== row.key) {
977!
1136
                return;
×
1137
            }
1138

1139
        } else {
1140
            this.selectionService.activeElement = null;
×
1141
            if (this.grid.crudService.cellInEditMode && !this.editMode) {
×
1142
                this.grid.crudService.updateCell(true, event);
×
1143
            }
1144
        }
1145

1146
        this.grid.navigation.setActiveNode({ row: this.rowIndex, column: this.visibleColumnIndex });
977✔
1147

1148
        const isTargetErrorIcon = event && event.target && event.target === this.errorIcon?.el.nativeElement
977✔
1149
        if (this.isInvalid && !isTargetErrorIcon) {
977✔
1150
            this.cdr.detectChanges();
1✔
1151
            this.openErrorTooltip();
1✔
1152
            this.grid.activeNodeChange.pipe(first()).subscribe(() => {
1✔
1153
                this.closeErrorTooltip();
×
1154
            });
1155
        }
1156
        this.selectionService.primaryButton = true;
977✔
1157
        if (this.cellSelectionMode === GridSelectionMode.multiple && this.selectionService.activeElement) {
977✔
1158
            if (this.selectionService.isInMap(this.selectionService.activeElement) && (event as any)?.ctrlKey && !(event as any)?.shiftKey) {
945✔
1159
                this.selectionService.remove(this.selectionService.activeElement);
3✔
1160
                shouldEmitSelection = true;
3✔
1161
            } else {
1162
                this.selectionService.add(this.selectionService.activeElement, false); // pointer events handle range generation
942✔
1163
                this.selectionService.keyboardStateOnFocus(node, this.grid.rangeSelected, this.nativeElement);
942✔
1164
            }
1165
        }
1166
        if (this.grid.isCellSelectable && shouldEmitSelection) {
977✔
1167
            this.zone.run(() => this.grid.selected.emit({ cell: this.getCellType(), event }));
950✔
1168
        }
1169
    }
1170

1171
    /**
1172
     * If the provided string matches the text in the cell, the text gets highlighted.
1173
     * ```typescript
1174
     * this.cell.highlightText('Cell Value', true);
1175
     * ```
1176
     *
1177
     * @memberof IgxGridCellComponent
1178
     */
1179
    public highlightText(text: string, caseSensitive?: boolean, exactMatch?: boolean): number {
1180
        return this.highlight && this.column.searchable ? this.highlight.highlight(text, caseSensitive, exactMatch) : 0;
163,338✔
1181
    }
1182

1183
    /**
1184
     * Clears the highlight of the text in the cell.
1185
     * ```typescript
1186
     * this.cell.clearHighLight();
1187
     * ```
1188
     *
1189
     * @memberof IgxGridCellComponent
1190
     */
1191
    public clearHighlight() {
1192
        if (this.highlight && this.column.searchable) {
40✔
1193
            this.highlight.clearHighlight();
40✔
1194
        }
1195
    }
1196

1197
    /**
1198
     * @hidden
1199
     * @internal
1200
     */
1201
    public calculateSizeToFit(range: any): number {
1202
        return this.platformUtil.getNodeSizeViaRange(range, this.nativeElement);
214✔
1203
    }
1204

1205
    /**
1206
     * @hidden
1207
     * @internal
1208
     */
1209
    public get searchMetadata() {
1210
        const meta = new Map<string, any>();
305,719✔
1211
        meta.set('pinned', this.grid.isRecordPinnedByViewIndex(this.intRow.index));
305,719✔
1212
        return meta;
305,719✔
1213
    }
1214

1215
    /**
1216
     * @hidden
1217
     * @internal
1218
     */
1219
    private _updateCRUDStatus(event?: Event) {
1220
        if (this.editMode) {
979✔
1221
            return;
48✔
1222
        }
1223

1224
        let editableArgs;
1225
        const crud = this.grid.crudService;
931✔
1226
        const editableCell = this.grid.crudService.cell;
931✔
1227
        const editMode = !!(crud.row || crud.cell);
931✔
1228

1229
        if (this.editable && editMode && !this.intRow.deleted) {
931✔
1230
            if (editableCell) {
88✔
1231
                editableArgs = this.grid.crudService.updateCell(false, event);
77✔
1232

1233
                /* This check is related with the following issue #6517:
1234
                 * when edit cell that belongs to a column which is sorted and press tab,
1235
                 * the next cell in edit mode is with wrong value /its context is not updated/;
1236
                 * So we reapply sorting before the next cell enters edit mode.
1237
                 * Also we need to keep the notifyChanges below, because of the current
1238
                 * change detection cycle when we have editing with enabled transactions
1239
                 */
1240
                if (this.grid.sortingExpressions.length && this.grid.sortingExpressions.indexOf(editableCell.column.field)) {
77!
1241
                    this.grid.cdr.detectChanges();
×
1242
                }
1243

1244
                if (editableArgs && editableArgs.cancel) {
77✔
1245
                    return true;
2✔
1246
                }
1247

1248
                crud.exitCellEdit(event);
75✔
1249
            }
1250
            this.grid.tbody.nativeElement.focus({ preventScroll: true });
86✔
1251
            this.grid.notifyChanges();
86✔
1252
            crud.enterEditMode(this, event);
86✔
1253
            return false;
86✔
1254
        }
1255

1256
        if (editableCell && crud.sameRow(this.cellID.rowID)) {
843✔
1257
            this.grid.crudService.updateCell(true, event);
1✔
1258
        } else if (editMode && !crud.sameRow(this.cellID.rowID)) {
842✔
1259
            this.grid.crudService.endEdit(true, event);
3✔
1260
        }
1261
    }
1262

1263
    private addPointerListeners(selection) {
1264
        if (selection !== GridSelectionMode.multiple) {
154,686✔
1265
            return;
604✔
1266
        }
1267
        this.nativeElement.addEventListener('pointerenter', this.pointerenter);
154,082✔
1268
        this.nativeElement.addEventListener('pointerup', this.pointerup);
154,082✔
1269
        this.nativeElement.addEventListener('focusout', this.focusout);
154,082✔
1270
    }
1271

1272
    private removePointerListeners(selection) {
1273
        if (selection !== GridSelectionMode.multiple) {
154,193✔
1274
            return;
852✔
1275
        }
1276
        this.nativeElement.removeEventListener('pointerenter', this.pointerenter);
153,341✔
1277
        this.nativeElement.removeEventListener('pointerup', this.pointerup);
153,341✔
1278
        this.nativeElement.removeEventListener('focusout', this.focusout);
153,341✔
1279
    }
1280

1281
    private getCellType(useRow?: boolean): CellType {
1282
        const rowID = useRow ? this.grid.createRow(this.intRow.index, this.intRow.data) : this.intRow.index;
3,393✔
1283
        return new IgxGridCell(this.grid, rowID, this.column);
3,393✔
1284
    }
1285
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc