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

IgniteUI / igniteui-angular / 16804852387

07 Aug 2025 12:45PM UTC coverage: 91.52% (+0.08%) from 91.44%
16804852387

Pull #16096

github

web-flow
Merge 22e4fbe2e into 6d3657091
Pull Request #16096: Address grids column headers accessibility issues - active descendant, what is announced by SRs - master

13509 of 15836 branches covered (85.31%)

41 of 42 new or added lines in 8 files covered. (97.62%)

13 existing lines in 2 files now uncovered.

27228 of 29751 relevant lines covered (91.52%)

34752.07 hits per line

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

91.86
/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>();
152,832✔
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,217,279✔
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
    /**
149
     * @hidden
150
     * @internal
151
     */
152
    protected get formGroup(): FormGroup {
153
        return this.grid.validation.getFormGroup(this.intRow.key);
5,914,832✔
154
    }
155

156
    /**
157
     * @hidden
158
     * @internal
159
     */
160
    @Input()
161
    public intRow: IgxRowDirective;
162

163
    /**
164
     * Gets the row of the cell.
165
     * ```typescript
166
     * let cellRow = this.cell.row;
167
     * ```
168
     *
169
     * @memberof IgxGridCellComponent
170
     */
171
    @Input()
172
    public get row(): RowType {
173
        return this.grid.createRow(this.intRow.index);
8,284✔
174
    }
175

176
    /**
177
     * Gets the data of the row of the cell.
178
     * ```typescript
179
     * let rowData = this.cell.rowData;
180
     * ```
181
     *
182
     * @memberof IgxGridCellComponent
183
     */
184
    @Input()
185
    public rowData: any;
186

187
    /**
188
     * @hidden
189
     * @internal
190
     */
191
    @Input()
192
    public columnData: any;
193

194
    /**
195
     * Sets/gets the template of the cell.
196
     * ```html
197
     * <ng-template #cellTemplate igxCell let-value>
198
     *   <div style="font-style: oblique; color:blueviolet; background:red">
199
     *       <span>{{value}}</span>
200
     *   </div>
201
     * </ng-template>
202
     * ```
203
     * ```typescript
204
     * @ViewChild('cellTemplate',{read: TemplateRef})
205
     * cellTemplate: TemplateRef<any>;
206
     * ```
207
     * ```typescript
208
     * this.cell.cellTemplate = this.cellTemplate;
209
     * ```
210
     * ```typescript
211
     * let template =  this.cell.cellTemplate;
212
     * ```
213
     *
214
     * @memberof IgxGridCellComponent
215
     */
216
    @Input()
217
    public cellTemplate: TemplateRef<any>;
218

219
    @Input()
220
    public cellValidationErrorTemplate: TemplateRef<any>;
221

222
    @Input()
223
    public pinnedIndicator: TemplateRef<any>;
224

225
    /**
226
     * Sets/gets the cell value.
227
     * ```typescript
228
     * this.cell.value = "Cell Value";
229
     * ```
230
     * ```typescript
231
     * let cellValue = this.cell.value;
232
     * ```
233
     *
234
     * @memberof IgxGridCellComponent
235
     */
236
    @Input()
237
    public value: any;
238

239
    /**
240
     * Gets the cell formatter.
241
     * ```typescript
242
     * let cellForamatter = this.cell.formatter;
243
     * ```
244
     *
245
     * @memberof IgxGridCellComponent
246
     */
247
    @Input()
248
    public formatter: (value: any, rowData?: any, columnData?: any) => any;
249

250
    /**
251
     * Gets the cell template context object.
252
     * ```typescript
253
     *  let context = this.cell.context();
254
     * ```
255
     *
256
     * @memberof IgxGridCellComponent
257
     */
258
    public get context(): IgxCellTemplateContext {
259
        const getCellType = () => this.getCellType(true);
650,415✔
260
        const ctx: IgxCellTemplateContext = {
650,415✔
261
            $implicit: this.value,
262
            additionalTemplateContext: this.column.additionalTemplateContext,
263
            get cell() {
264
                /* Turns the `cell` property from the template context object into lazy-evaluated one.
265
                 * Otherwise on each detection cycle the cell template is recreating N cell instances where
266
                 * N = number of visible cells in the grid, leading to massive performance degradation in large grids.
267
                 */
268
                return getCellType();
1,998✔
269
            }
270
        };
271
        if (this.editMode) {
650,415✔
272
            ctx.formControl = this.formControl;
2,469✔
273
        }
274
        if (this.isInvalid) {
650,415✔
275
            ctx.defaultErrorTemplate = this.defaultErrorTemplate;
429✔
276
        }
277
        return ctx;
650,415✔
278
    }
279

280
    /**
281
     * Gets the cell template.
282
     * ```typescript
283
     * let template = this.cell.template;
284
     * ```
285
     *
286
     * @memberof IgxGridCellComponent
287
     */
288
    public get template(): TemplateRef<any> {
289
        if (this.editMode && this.formGroup) {
325,160✔
290
            const inlineEditorTemplate = this.column.inlineEditorTemplate;
1,233✔
291
            return inlineEditorTemplate ? inlineEditorTemplate : this.inlineEditorTemplate;
1,233✔
292
        }
293
        if (this.cellTemplate) {
323,927✔
294
            return this.cellTemplate;
755✔
295
        }
296
        if (this.grid.rowEditable && this.intRow.addRowUI) {
323,172✔
297
            return this.addRowCellTemplate;
1,918✔
298
        }
299
        return this.defaultCellTemplate;
321,254✔
300
    }
301

302
    /**
303
     * Gets the pinned indicator template.
304
     * ```typescript
305
     * let template = this.cell.pinnedIndicatorTemplate;
306
     * ```
307
     *
308
     * @memberof IgxGridCellComponent
309
     */
310
    public get pinnedIndicatorTemplate() {
311
        if (this.pinnedIndicator) {
325,112!
312
            return this.pinnedIndicator;
×
313
        }
314
        return this.defaultPinnedIndicator;
325,112✔
315
    }
316

317
    /**
318
     * Gets the `id` of the grid in which the cell is stored.
319
     * ```typescript
320
     * let gridId = this.cell.gridID;
321
     * ```
322
     *
323
     * @memberof IgxGridCellComponent
324
     */
325
    public get gridID(): any {
326
        return this.intRow.gridID;
304,111✔
327
    }
328

329

330
    /**
331
     * Gets the `index` of the row where the cell is stored.
332
     * ```typescript
333
     * let rowIndex = this.cell.rowIndex;
334
     * ```
335
     *
336
     * @memberof IgxGridCellComponent
337
     */
338
    @HostBinding('attr.data-rowIndex')
339
    public get rowIndex(): number {
340
        return this.intRow.index;
6,082,456✔
341
    }
342

343
    /**
344
     * Gets the `index` of the cell column.
345
     * ```typescript
346
     * let columnIndex = this.cell.columnIndex;
347
     * ```
348
     *
349
     * @memberof IgxGridCellComponent
350
     */
351
    public get columnIndex(): number {
352
        return this.column.index;
17,841✔
353
    }
354

355
    /**
356
     * Returns the column visible index.
357
     * ```typescript
358
     * let visibleColumnIndex = this.cell.visibleColumnIndex;
359
     * ```
360
     *
361
     * @memberof IgxGridCellComponent
362
     */
363
    @HostBinding('attr.data-visibleIndex')
364
    @Input()
365
    public get visibleColumnIndex() {
366
        return this.column.columnLayoutChild ? this.column.visibleIndex : this._vIndex;
6,085,136✔
367
    }
368

369
    public set visibleColumnIndex(val) {
370
        this._vIndex = val;
159,390✔
371
    }
372

373
    /**
374
     * Gets the ID of the cell.
375
     * ```typescript
376
     * let cellID = this.cell.cellID;
377
     * ```
378
     *
379
     * @memberof IgxGridCellComponent
380
     */
381
    public get cellID() {
382
        const primaryKey = this.grid.primaryKey;
460✔
383
        const rowID = primaryKey ? this.rowData[primaryKey] : this.rowData;
460✔
384
        return { rowID, columnID: this.columnIndex, rowIndex: this.rowIndex };
460✔
385
    }
386

387
    @HostBinding('attr.id')
388
    public get attrCellID() {
389
        return `${this.intRow.gridID}_${this.rowIndex}_${this.visibleColumnIndex}`;
1,215,408✔
390
    }
391

392
    @HostBinding('attr.title')
393
    public get title() {
394
        if (this.editMode || this.cellTemplate || this.errorShowing) {
1,215,421✔
395
            return '';
5,396✔
396
        }
397

398
        if (this.formatter) {
1,210,025✔
399
            return this.formatter(this.value, this.rowData, this.columnData);
22,212✔
400
        }
401

402
        const args = this.column.pipeArgs;
1,187,813✔
403
        const locale = this.grid.locale;
1,187,813✔
404

405
        switch (this.column.dataType) {
1,187,813✔
406
            case GridColumnDataType.Percent:
407
                return formatPercent(this.value, locale, args.digitsInfo);
427✔
408
            case GridColumnDataType.Currency:
409
                return formatCurrency(this.value, this.currencyCode, args.display, args.digitsInfo, locale);
20,400✔
410
            case GridColumnDataType.Date:
411
            case GridColumnDataType.DateTime:
412
            case GridColumnDataType.Time:
413
                return formatDate(this.value, args.format, locale, args.timezone);
170,674✔
414
        }
415
        return this.value;
996,312✔
416
    }
417

418
    @HostBinding('class.igx-grid__td--bool-true')
419
    public get booleanClass() {
420
        return this.column.dataType === 'boolean' && this.value;
1,215,408✔
421
    }
422

423
    /**
424
     * Returns a reference to the nativeElement of the cell.
425
     * ```typescript
426
     * let cellNativeElement = this.cell.nativeElement;
427
     * ```
428
     *
429
     * @memberof IgxGridCellComponent
430
     */
431
    public get nativeElement(): HTMLElement {
432
        return this.element.nativeElement;
1,330,629✔
433
    }
434

435
    /**
436
     * @hidden
437
     * @internal
438
     */
439
    @Input()
440
    public get cellSelectionMode() {
441
        return this._cellSelection;
306,693✔
442
    }
443

444
    public set cellSelectionMode(value) {
445
        if (this._cellSelection === value) {
153,200✔
446
            return;
152,228✔
447
        }
448
        this.zone.runOutsideAngular(() => {
972✔
449
            if (value === GridSelectionMode.multiple) {
972✔
450
                this.addPointerListeners(value);
60✔
451
            } else {
452
                this.removePointerListeners(this._cellSelection);
912✔
453
            }
454
        });
455
        this._cellSelection = value;
972✔
456
    }
457

458
    /**
459
     * @hidden
460
     * @internal
461
     */
462
    @Input()
463
    public set lastSearchInfo(value: ISearchInfo) {
464
        this._lastSearchInfo = value;
158,132✔
465
        this.highlightText(this._lastSearchInfo.searchText, this._lastSearchInfo.caseSensitive, this._lastSearchInfo.exactMatch);
158,132✔
466
    }
467

468
    /**
469
     * @hidden
470
     * @internal
471
     */
472
    @Input()
473
    @HostBinding('class.igx-grid__td--pinned-last')
474
    public lastPinned = false;
152,832✔
475

476
    /**
477
     * @hidden
478
     * @internal
479
     */
480
    @Input()
481
    @HostBinding('class.igx-grid__td--pinned-first')
482
    public firstPinned = false;
152,832✔
483

484
    /**
485
     * Returns whether the cell is in edit mode.
486
     */
487
    @Input({ transform: booleanAttribute })
488
    @HostBinding('class.igx-grid__td--editing')
489
    public editMode = false;
152,832✔
490

491
    /**
492
     * Sets/get the `role` property of the cell.
493
     * Default value is `"gridcell"`.
494
     * ```typescript
495
     * this.cell.role = 'grid-cell';
496
     * ```
497
     * ```typescript
498
     * let cellRole = this.cell.role;
499
     * ```
500
     *
501
     * @memberof IgxGridCellComponent
502
     */
503
    @HostBinding('attr.role')
504
    public role = 'gridcell';
152,832✔
505

506
    /**
507
     * Gets whether the cell is editable.
508
     * ```typescript
509
     * let isCellReadonly = this.cell.readonly;
510
     * ```
511
     *
512
     * @memberof IgxGridCellComponent
513
     */
514
    @HostBinding('attr.aria-readonly')
515
    public get readonly(): boolean {
516
        return !this.editable;
1,215,409✔
517
    }
518

519
    /** @hidden @internal */
520
    @HostBinding('attr.aria-describedby')
521
    public get ariaDescribeBy() {
522
        return this.isInvalid ? this.ariaErrorMessage : null;
1,216,495✔
523
    }
524

525
    /** @hidden @internal */
526
    public get ariaErrorMessage() {
527
        return this.grid.id + '_' + this.column.field + '_' + this.intRow.index + '_error';
253✔
528
    }
529

530
    /**
531
     * @hidden
532
     * @internal
533
     */
534
    @HostBinding('class.igx-grid__td--invalid')
535
    @HostBinding('attr.aria-invalid')
536
    public get isInvalid() {
537
        if (this.formGroup) {
4,624,994✔
538
            const isInvalid = this.grid.validation?.isFieldInvalid(this.formGroup, this.column?.field);
60,928✔
539
            return !this.intRow.deleted && isInvalid;
60,928✔
540
        }
541
        return false;
4,564,066✔
542
    }
543

544
    /**
545
     * @hidden
546
     * @internal
547
     */
548
    @HostBinding('class.igx-grid__td--valid')
549
    public get isValidAfterEdit() {
550
        if (this.formGroup) {
1,215,408✔
551
            const isValidAfterEdit = this.grid.validation?.isFieldValidAfterEdit(this.formGroup, this.column?.field);
11,056✔
552
            return this.editMode && isValidAfterEdit;
11,056✔
553
        }
554
        return false;
1,204,352✔
555
    }
556

557
    /**
558
     * Gets the formControl responsible for value changes and validation for this cell.
559
     */
560
    protected get formControl(): FormControl {
561
        return this.grid.validation.getFormControl(this.intRow.key, this.column.field) as FormControl;
54,404✔
562
    }
563

564
    public get gridRowSpan(): number {
565
        return this.column.gridRowSpan;
198✔
566
    }
567

568
    public get gridColumnSpan(): number {
569
        return this.column.gridColumnSpan;
198✔
570
    }
571

572
    public get rowEnd(): number {
573
        return this.column.rowEnd;
×
574
    }
575

576
    public get colEnd(): number {
577
        return this.column.colEnd;
×
578
    }
579

580
    public get rowStart(): number {
581
        return this.column.rowStart;
×
582
    }
583

584
    public get colStart(): number {
585
        return this.column.colStart;
×
586
    }
587

588
    /**
589
     * Gets the width of the cell.
590
     * ```typescript
591
     * let cellWidth = this.cell.width;
592
     * ```
593
     *
594
     * @memberof IgxGridCellComponent
595
     */
596
    @Input()
597
    public width = '';
152,832✔
598

599
    /**
600
     * @hidden
601
     */
602
    @Input()
603
    @HostBinding('class.igx-grid__td--active')
604
    public active = false;
152,832✔
605

606
    @HostBinding('attr.aria-selected')
607
    public get ariaSelected() {
608
        return this.selected || this.column.selected || this.intRow.selected;
1,215,408✔
609
    }
610

611
    /**
612
     * Gets whether the cell is selected.
613
     * ```typescript
614
     * let isSelected = this.cell.selected;
615
     * ```
616
     *
617
     * @memberof IgxGridCellComponent
618
     */
619
    @HostBinding('class.igx-grid__td--selected')
620
    public get selected() {
621
        return this.selectionService.selected(this.selectionNode);
2,432,901✔
622
    }
623

624
    /**
625
     * Selects/deselects the cell.
626
     * ```typescript
627
     * this.cell.selected = true.
628
     * ```
629
     *
630
     * @memberof IgxGridCellComponent
631
     */
632
    public set selected(val: boolean) {
633
        const node = this.selectionNode;
1✔
634
        if (val) {
1!
635
            this.selectionService.add(node);
1✔
636
        } else {
637
            this.selectionService.remove(node);
×
638
        }
639
        this.grid.notifyChanges();
1✔
640
    }
641

642
    /**
643
     * Gets whether the cell column is selected.
644
     * ```typescript
645
     * let isCellColumnSelected = this.cell.columnSelected;
646
     * ```
647
     *
648
     * @memberof IgxGridCellComponent
649
     */
650
    @HostBinding('class.igx-grid__td--column-selected')
651
    public get columnSelected() {
652
        return this.selectionService.isColumnSelected(this.column.field);
1,215,408✔
653
    }
654

655
    /**
656
     * Sets the current edit value while a cell is in edit mode.
657
     * Only for cell editing mode.
658
     * ```typescript
659
     * this.cell.editValue = value;
660
     * ```
661
     *
662
     * @memberof IgxGridCellComponent
663
     */
664
    public set editValue(value) {
665
        if (this.grid.crudService.cellInEditMode) {
44✔
666
            this.grid.crudService.cell.editValue = value;
44✔
667
        }
668
    }
669

670
    /**
671
     * Gets the current edit value while a cell is in edit mode.
672
     * Only for cell editing mode.
673
     * ```typescript
674
     * let editValue = this.cell.editValue;
675
     * ```
676
     *
677
     * @memberof IgxGridCellComponent
678
     */
679
    public get editValue() {
680
        if (this.grid.crudService.cellInEditMode) {
163✔
681
            return this.grid.crudService.cell.editValue;
163✔
682
        }
683
    }
684

685
    /**
686
     * Returns whether the cell is editable.
687
     */
688
    public get editable(): boolean {
689
        return this.column.editable && !this.intRow.disabled;
1,216,679✔
690
    }
691

692
    /**
693
     * @hidden
694
     */
695
    @Input()
696
    @HostBinding('class.igx-grid__td--row-pinned-first')
697
    public displayPinnedChip = false;
152,832✔
698

699
    @HostBinding('style.min-height.px')
700
    protected get minHeight() {
701
        if ((this.grid as any).isCustomSetRowHeight) {
1,215,408✔
702
            return this.grid.renderedRowHeight;
464✔
703
        }
704
    }
705

706
    @HostBinding('attr.aria-rowindex')
707
    protected get ariaRowIndex(): number {
708
        return this.rowIndex + 1;
1,215,408✔
709
    }
710

711
    @HostBinding('attr.aria-colindex')
712
    protected get ariaColIndex(): number {
713
        return this.visibleColumnIndex + 1;
1,215,408✔
714
    }
715

716
    @ViewChild('defaultCell', { read: TemplateRef, static: true })
717
    protected defaultCellTemplate: TemplateRef<any>;
718

719
    @ViewChild('defaultPinnedIndicator', { read: TemplateRef, static: true })
720
    protected defaultPinnedIndicator: TemplateRef<any>;
721

722
    @ViewChild('inlineEditor', { read: TemplateRef, static: true })
723
    protected inlineEditorTemplate: TemplateRef<any>;
724

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

728
    @ViewChild(IgxTextHighlightDirective, { read: IgxTextHighlightDirective })
729
    protected set highlight(value: IgxTextHighlightDirective) {
730
        this._highlight = value;
154,885✔
731

732
        if (this._highlight && this.grid.lastSearchInfo.searchText) {
154,885✔
733
            this._highlight.highlight(this.grid.lastSearchInfo.searchText,
399✔
734
                this.grid.lastSearchInfo.caseSensitive,
735
                this.grid.lastSearchInfo.exactMatch);
736
            this._highlight.activateIfNecessary();
399✔
737
        }
738
    }
739

740
    protected get highlight() {
741
        return this._highlight;
353,626✔
742
    }
743

744
    protected get selectionNode(): ISelectionNode {
745
        return {
2,434,790✔
746
            row: this.rowIndex,
747
            column: this.column.columnLayoutChild ? this.column.parent.visibleIndex : this.visibleColumnIndex,
2,434,790✔
748
            layout: this.column.columnLayoutChild ? {
2,434,790✔
749
                rowStart: this.column.rowStart,
750
                colStart: this.column.colStart,
751
                rowEnd: this.column.rowEnd,
752
                colEnd: this.column.colEnd,
753
                columnVisibleIndex: this.visibleColumnIndex
754
            } : null
755
        };
756
    }
757

758
    /**
759
     * Sets/gets the highlight class of the cell.
760
     * Default value is `"igx-highlight"`.
761
     * ```typescript
762
     * let highlightClass = this.cell.highlightClass;
763
     * ```
764
     * ```typescript
765
     * this.cell.highlightClass = 'igx-cell-highlight';
766
     * ```
767
     *
768
     * @memberof IgxGridCellComponent
769
     */
770
    public highlightClass = 'igx-highlight';
152,832✔
771

772
    /**
773
     * Sets/gets the active highlight class class of the cell.
774
     * Default value is `"igx-highlight__active"`.
775
     * ```typescript
776
     * let activeHighlightClass = this.cell.activeHighlightClass;
777
     * ```
778
     * ```typescript
779
     * this.cell.activeHighlightClass = 'igx-cell-highlight_active';
780
     * ```
781
     *
782
     * @memberof IgxGridCellComponent
783
     */
784
    public activeHighlightClass = 'igx-highlight__active';
152,832✔
785

786
    /** @hidden @internal */
787
    public get step(): number {
788
        const digitsInfo = this.column.pipeArgs.digitsInfo;
218✔
789
        if (!digitsInfo) {
218!
UNCOV
790
            return 1;
×
791
        }
792
        const step = +digitsInfo.substr(digitsInfo.indexOf('.') + 1, 1);
218✔
793
        return 1 / (Math.pow(10, step));
218✔
794
    }
795

796
    /** @hidden @internal */
797
    public get currencyCode(): string {
798
        return this.column.pipeArgs.currencyCode ?
57,432✔
799
            this.column.pipeArgs.currencyCode : getLocaleCurrencyCode(this.grid.locale);
800
    }
801

802
    /** @hidden @internal */
803
    public get currencyCodeSymbol(): string {
804
        return getCurrencySymbol(this.currencyCode, 'wide', this.grid.locale);
4✔
805
    }
806

807
    protected _lastSearchInfo: ISearchInfo;
808
    private _highlight: IgxTextHighlightDirective;
809
    private _cellSelection: GridSelectionMode = GridSelectionMode.multiple;
152,832✔
810
    private _vIndex = -1;
152,832✔
811

812
    constructor(
813
        protected selectionService: IgxGridSelectionService,
152,832✔
814
        @Inject(IGX_GRID_BASE) public grid: GridType,
152,832✔
815
        @Inject(IgxOverlayService) protected overlayService: IgxOverlayService,
152,832✔
816
        public cdr: ChangeDetectorRef,
152,832✔
817
        private element: ElementRef<HTMLElement>,
152,832✔
818
        protected zone: NgZone,
152,832✔
819
        private touchManager: HammerGesturesManager,
152,832✔
820
        protected platformUtil: PlatformUtil
152,832✔
821
    ) { }
822

823
    /**
824
     * @hidden
825
     * @internal
826
     */
827
    @HostListener('dblclick', ['$event'])
828
    public onDoubleClick = (event: MouseEvent) => {
152,832✔
829
        if (event.type === 'doubletap') {
151✔
830
            // prevent double-tap to zoom on iOS
831
            event.preventDefault();
1✔
832
        }
833
        if (this.editable && !this.editMode && !this.intRow.deleted && !this.grid.crudService.rowEditingBlocked) {
151✔
834
            this.grid.crudService.enterEditMode(this, event as Event);
145✔
835
        }
836

837
        this.grid.doubleClick.emit({
151✔
838
            cell: this.getCellType(),
839
            event
840
        });
841
    };
842

843
    /**
844
     * @hidden
845
     * @internal
846
     */
847
    @HostListener('click', ['$event'])
848
    public onClick(event: MouseEvent) {
849
        this.grid.cellClick.emit({
263✔
850
            cell: this.getCellType(),
851
            event
852
        });
853
    }
854

855
    /**
856
     * @hidden
857
     * @internal
858
     */
859
    public ngOnInit() {
860
        this.zone.runOutsideAngular(() => {
152,832✔
861
            this.nativeElement.addEventListener('pointerdown', this.pointerdown);
152,832✔
862
            this.addPointerListeners(this.cellSelectionMode);
152,832✔
863
        });
864
        if (this.platformUtil.isIOS) {
152,832✔
865
            this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
40✔
866
                cssProps: {} /* don't disable user-select, etc */
867
            });
868
        }
869

870
    }
871

872
    public ngAfterViewInit() {
873
        this.errorTooltip.changes.pipe(takeUntil(this._destroy$)).subscribe(() => {
152,832✔
874
            if (this.errorTooltip.length > 0 && this.active) {
44✔
875
                // error ocurred
876
                this.cdr.detectChanges();
25✔
877
                this.openErrorTooltip();
25✔
878
            }
879
        });
880
    }
881

882
    /**
883
     * @hidden
884
     * @internal
885
     */
886
    public errorShowing = false;
152,832✔
887

888
    private openErrorTooltip() {
889
        const tooltip = this.errorTooltip.first;
26✔
890
        tooltip.open(
26✔
891
            {
892
                target: this.errorIcon.el.nativeElement,
893
                closeOnOutsideClick: true,
894
                excludeFromOutsideClick: [this.nativeElement],
895
                closeOnEscape: false,
896
                outlet: this.grid.outlet,
897
                modal: false,
898
                positionStrategy: new AutoPositionStrategy({
899
                    horizontalStartPoint: HorizontalAlignment.Center,
900
                    horizontalDirection: HorizontalAlignment.Center,
901
                    openAnimation: useAnimation(scaleInCenter, { params: { duration: '150ms' } }),
902
                    closeAnimation: useAnimation(fadeOut, { params: { duration: '75ms' } })
903
                })
904
            }
905
        );
906
    }
907

908
    /**
909
     * @hidden
910
     * @internal
911
     */
912
    public ngOnDestroy() {
913
        this.zone.runOutsideAngular(() => {
151,487✔
914
            this.nativeElement.removeEventListener('pointerdown', this.pointerdown);
151,487✔
915
            this.removePointerListeners(this.cellSelectionMode);
151,487✔
916
        });
917
        this.touchManager.destroy();
151,487✔
918
        this._destroy$.next();
151,487✔
919
        this._destroy$.complete();
151,487✔
920
    }
921

922
    /**
923
     * @hidden
924
     * @internal
925
     */
926
    public ngOnChanges(changes: SimpleChanges): void {
927
        if (changes.editMode && changes.editMode.currentValue && this.formControl) {
291,766✔
928
            // ensure when values change, form control is forced to be marked as touche.
929
            this.formControl.valueChanges.pipe(takeWhile(() => this.editMode)).subscribe(() => this.formControl.markAsTouched());
400✔
930
            // while in edit mode subscribe to value changes on the current form control and set to editValue
931
            this.formControl.statusChanges.pipe(takeWhile(() => this.editMode)).subscribe(status => {
400✔
932
                if (status === 'INVALID' && this.errorTooltip.length > 0) {
190!
UNCOV
933
                    this.cdr.detectChanges();
×
934
                    const tooltip = this.errorTooltip.first;
×
935
                    this.resizeAndRepositionOverlayById(tooltip.overlayId, this.errorTooltip.first.element.offsetWidth);
×
936
                }
937
            });
938
        }
939
        if (changes.value && !changes.value.firstChange) {
291,766✔
940
            if (this.highlight) {
47,792✔
941
                this.highlight.lastSearchInfo.searchText = this.grid.lastSearchInfo.searchText;
45,400✔
942
                this.highlight.lastSearchInfo.caseSensitive = this.grid.lastSearchInfo.caseSensitive;
45,400✔
943
                this.highlight.lastSearchInfo.exactMatch = this.grid.lastSearchInfo.exactMatch;
45,400✔
944
            }
945
            const isInEdit = this.grid.rowEditable ? this.row.inEditMode : this.editMode;
47,792✔
946
            if (this.formControl && this.formControl.value !== changes.value.currentValue && !isInEdit) {
47,792✔
947
                this.formControl.setValue(changes.value.currentValue);
131✔
948
            }
949
        }
950
    }
951

952

953

954
    /**
955
     * @hidden @internal
956
     */
957
    private resizeAndRepositionOverlayById(overlayId: string, newSize: number) {
UNCOV
958
        const overlay = this.overlayService.getOverlayById(overlayId);
×
959
        if (!overlay) return;
×
960
        overlay.initialSize.width = newSize;
×
961
        overlay.elementRef.nativeElement.parentElement.style.width = newSize + 'px';
×
962
        this.overlayService.reposition(overlayId);
×
963
    }
964

965
    /**
966
     * Starts/ends edit mode for the cell.
967
     *
968
     * ```typescript
969
     * cell.setEditMode(true);
970
     * ```
971
     */
972
    public setEditMode(value: boolean): void {
973
        if (this.intRow.deleted) {
30!
UNCOV
974
            return;
×
975
        }
976
        if (this.editable && value) {
30✔
977
            if (this.grid.crudService.cellInEditMode) {
26✔
978
                this.grid.gridAPI.update_cell(this.grid.crudService.cell);
5✔
979
                this.grid.crudService.endCellEdit();
5✔
980
            }
981
            this.grid.crudService.enterEditMode(this);
26✔
982
        } else {
983
            this.grid.crudService.endCellEdit();
4✔
984
        }
985
        this.grid.notifyChanges();
30✔
986
    }
987

988
    /**
989
     * Sets new value to the cell.
990
     * ```typescript
991
     * this.cell.update('New Value');
992
     * ```
993
     *
994
     * @memberof IgxGridCellComponent
995
     */
996
    // TODO: Refactor
997
    public update(val: any) {
998
        if (this.intRow.deleted) {
34!
UNCOV
999
            return;
×
1000
        }
1001

1002
        let cell = this.grid.crudService.cell;
34✔
1003
        if (!cell) {
34✔
1004
            cell = this.grid.crudService.createCell(this);
14✔
1005
        }
1006
        cell.editValue = val;
34✔
1007
        this.grid.gridAPI.update_cell(cell);
34✔
1008
        this.grid.crudService.endCellEdit();
34✔
1009
        this.cdr.markForCheck();
34✔
1010
    }
1011

1012
    /**
1013
     *
1014
     * @hidden
1015
     * @internal
1016
     */
1017
    public pointerdown = (event: PointerEvent) => {
152,832✔
1018
        if (this.cellSelectionMode !== GridSelectionMode.multiple) {
428✔
1019
            this.activate(event);
23✔
1020
            return;
23✔
1021
        }
1022
        if (!this.platformUtil.isLeftClick(event)) {
405✔
1023
            event.preventDefault();
4✔
1024
            this.grid.navigation.setActiveNode({ rowIndex: this.rowIndex, colIndex: this.visibleColumnIndex });
4✔
1025
            this.selectionService.addKeyboardRange();
4✔
1026
            this.selectionService.initKeyboardState();
4✔
1027
            this.selectionService.primaryButton = false;
4✔
1028
            // Ensure RMB Click on edited cell does not end cell editing
1029
            if (!this.selected) {
4✔
1030
                this.grid.crudService.updateCell(true, event);
2✔
1031
            }
1032
            return;
4✔
1033
        } else {
1034
            this.selectionService.primaryButton = true;
401✔
1035
        }
1036
        this.selectionService.pointerDown(this.selectionNode, event.shiftKey, event.ctrlKey);
401✔
1037
        this.activate(event);
401✔
1038
    };
1039

1040
    /**
1041
     *
1042
     * @hidden
1043
     * @internal
1044
     */
1045
    public pointerenter = (event: PointerEvent) => {
152,832✔
1046
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
118✔
1047
        if (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID || this.grid.navigation.activeNode.gridID !== this.gridID)) {
118✔
1048
            return;
3✔
1049
        }
1050
        const dragMode = this.selectionService.pointerEnter(this.selectionNode, event);
115✔
1051
        if (dragMode) {
115✔
1052
            this.grid.cdr.detectChanges();
114✔
1053
        }
1054
    };
1055

1056
    /**
1057
     * @hidden
1058
     * @internal
1059
     */
1060
    public focusout = () => {
152,832✔
1061
        this.closeErrorTooltip();
48✔
1062
    }
1063

1064
    private closeErrorTooltip() {
1065
        const tooltip = this.errorTooltip.first;
48✔
1066
        if (tooltip) {
48!
UNCOV
1067
            tooltip.close();
×
1068
        }
1069
    }
1070

1071
    /**
1072
     * @hidden
1073
     * @internal
1074
     */
1075
    public pointerup = (event: PointerEvent) => {
152,832✔
1076
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
402✔
1077
        if (!this.platformUtil.isLeftClick(event) || (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID ||
402✔
1078
            this.grid.navigation.activeNode.gridID !== this.gridID))) {
1079
            return;
4✔
1080
        }
1081
        if (this.selectionService.pointerUp(this.selectionNode, this.grid.rangeSelected)) {
398✔
1082
            this.grid.cdr.detectChanges();
49✔
1083
        }
1084
    };
1085

1086
    /**
1087
     * @hidden
1088
     * @internal
1089
     */
1090
    public activate(event: FocusEvent | KeyboardEvent) {
1091
        const node = this.selectionNode;
974✔
1092
        let shouldEmitSelection = !this.selectionService.isActiveNode(node);
974✔
1093

1094
        if (this.selectionService.primaryButton) {
974!
1095
            const currentActive = this.selectionService.activeElement;
974✔
1096
            if (this.cellSelectionMode === GridSelectionMode.single && (event as any)?.ctrlKey && this.selected) {
974✔
1097
                this.selectionService.activeElement = null;
1✔
1098
                shouldEmitSelection = true;
1✔
1099
            } else {
1100
                this.selectionService.activeElement = node;
973✔
1101
            }
1102
            const cancel = this._updateCRUDStatus(event);
974✔
1103
            if (cancel) {
974✔
1104
                this.selectionService.activeElement = currentActive;
2✔
1105
                return;
2✔
1106
            }
1107

1108
            const activeElement = this.selectionService.activeElement;
972✔
1109
            const row = activeElement ? this.grid.gridAPI.get_row_by_index(activeElement.row) : null;
972✔
1110
            if (this.grid.crudService.rowEditingBlocked && row && this.intRow.key !== row.key) {
972!
UNCOV
1111
                return;
×
1112
            }
1113

1114
        } else {
UNCOV
1115
            this.selectionService.activeElement = null;
×
1116
            if (this.grid.crudService.cellInEditMode && !this.editMode) {
×
1117
                this.grid.crudService.updateCell(true, event);
×
1118
            }
1119
        }
1120

1121
        this.grid.navigation.setActiveNode({ row: this.rowIndex, column: this.visibleColumnIndex });
972✔
1122

1123
        const isTargetErrorIcon = event && event.target && event.target === this.errorIcon?.el.nativeElement
972✔
1124
        if (this.isInvalid && !isTargetErrorIcon) {
972✔
1125
            this.cdr.detectChanges();
1✔
1126
            this.openErrorTooltip();
1✔
1127
            this.grid.activeNodeChange.pipe(first()).subscribe(() => {
1✔
UNCOV
1128
                this.closeErrorTooltip();
×
1129
            });
1130
        }
1131
        this.selectionService.primaryButton = true;
972✔
1132
        if (this.cellSelectionMode === GridSelectionMode.multiple && this.selectionService.activeElement) {
972✔
1133
            if (this.selectionService.isInMap(this.selectionService.activeElement) && (event as any)?.ctrlKey && !(event as any)?.shiftKey) {
940✔
1134
                this.selectionService.remove(this.selectionService.activeElement);
3✔
1135
                shouldEmitSelection = true;
3✔
1136
            } else {
1137
                this.selectionService.add(this.selectionService.activeElement, false); // pointer events handle range generation
937✔
1138
                this.selectionService.keyboardStateOnFocus(node, this.grid.rangeSelected, this.nativeElement);
937✔
1139
            }
1140
        }
1141
        if (this.grid.isCellSelectable && shouldEmitSelection) {
972✔
1142
            this.zone.run(() => this.grid.selected.emit({ cell: this.getCellType(), event }));
945✔
1143
        }
1144
    }
1145

1146
    /**
1147
     * If the provided string matches the text in the cell, the text gets highlighted.
1148
     * ```typescript
1149
     * this.cell.highlightText('Cell Value', true);
1150
     * ```
1151
     *
1152
     * @memberof IgxGridCellComponent
1153
     */
1154
    public highlightText(text: string, caseSensitive?: boolean, exactMatch?: boolean): number {
1155
        return this.highlight && this.column.searchable ? this.highlight.highlight(text, caseSensitive, exactMatch) : 0;
161,229✔
1156
    }
1157

1158
    /**
1159
     * Clears the highlight of the text in the cell.
1160
     * ```typescript
1161
     * this.cell.clearHighLight();
1162
     * ```
1163
     *
1164
     * @memberof IgxGridCellComponent
1165
     */
1166
    public clearHighlight() {
1167
        if (this.highlight && this.column.searchable) {
40✔
1168
            this.highlight.clearHighlight();
40✔
1169
        }
1170
    }
1171

1172
    /**
1173
     * @hidden
1174
     * @internal
1175
     */
1176
    public calculateSizeToFit(range: any): number {
1177
        return this.platformUtil.getNodeSizeViaRange(range, this.nativeElement);
214✔
1178
    }
1179

1180
    /**
1181
     * @hidden
1182
     * @internal
1183
     */
1184
    public get searchMetadata() {
1185
        const meta = new Map<string, any>();
303,968✔
1186
        meta.set('pinned', this.grid.isRecordPinnedByViewIndex(this.intRow.index));
303,968✔
1187
        return meta;
303,968✔
1188
    }
1189

1190
    /**
1191
     * @hidden
1192
     * @internal
1193
     */
1194
    private _updateCRUDStatus(event?: Event) {
1195
        if (this.editMode) {
974✔
1196
            return;
48✔
1197
        }
1198

1199
        let editableArgs;
1200
        const crud = this.grid.crudService;
926✔
1201
        const editableCell = this.grid.crudService.cell;
926✔
1202
        const editMode = !!(crud.row || crud.cell);
926✔
1203

1204
        if (this.editable && editMode && !this.intRow.deleted) {
926✔
1205
            if (editableCell) {
88✔
1206
                editableArgs = this.grid.crudService.updateCell(false, event);
77✔
1207

1208
                /* This check is related with the following issue #6517:
1209
                 * when edit cell that belongs to a column which is sorted and press tab,
1210
                 * the next cell in edit mode is with wrong value /its context is not updated/;
1211
                 * So we reapply sorting before the next cell enters edit mode.
1212
                 * Also we need to keep the notifyChanges below, because of the current
1213
                 * change detection cycle when we have editing with enabled transactions
1214
                 */
1215
                if (this.grid.sortingExpressions.length && this.grid.sortingExpressions.indexOf(editableCell.column.field)) {
77!
UNCOV
1216
                    this.grid.cdr.detectChanges();
×
1217
                }
1218

1219
                if (editableArgs && editableArgs.cancel) {
77✔
1220
                    return true;
2✔
1221
                }
1222

1223
                crud.exitCellEdit(event);
75✔
1224
            }
1225
            this.grid.tbody.nativeElement.focus({ preventScroll: true });
86✔
1226
            this.grid.notifyChanges();
86✔
1227
            crud.enterEditMode(this, event);
86✔
1228
            return false;
86✔
1229
        }
1230

1231
        if (editableCell && crud.sameRow(this.cellID.rowID)) {
838✔
1232
            this.grid.crudService.updateCell(true, event);
1✔
1233
        } else if (editMode && !crud.sameRow(this.cellID.rowID)) {
837✔
1234
            this.grid.crudService.endEdit(true, event);
3✔
1235
        }
1236
    }
1237

1238
    private addPointerListeners(selection) {
1239
        if (selection !== GridSelectionMode.multiple) {
152,892✔
1240
            return;
604✔
1241
        }
1242
        this.nativeElement.addEventListener('pointerenter', this.pointerenter);
152,288✔
1243
        this.nativeElement.addEventListener('pointerup', this.pointerup);
152,288✔
1244
        this.nativeElement.addEventListener('focusout', this.focusout);
152,288✔
1245
    }
1246

1247
    private removePointerListeners(selection) {
1248
        if (selection !== GridSelectionMode.multiple) {
152,399✔
1249
            return;
852✔
1250
        }
1251
        this.nativeElement.removeEventListener('pointerenter', this.pointerenter);
151,547✔
1252
        this.nativeElement.removeEventListener('pointerup', this.pointerup);
151,547✔
1253
        this.nativeElement.removeEventListener('focusout', this.focusout);
151,547✔
1254
    }
1255

1256
    private getCellType(useRow?: boolean): CellType {
1257
        const rowID = useRow ? this.grid.createRow(this.intRow.index, this.intRow.data) : this.intRow.index;
3,357✔
1258
        return new IgxGridCell(this.grid, rowID, this.column);
3,357✔
1259
    }
1260
}
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