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

IgniteUI / igniteui-angular / 15972967310

30 Jun 2025 12:31PM UTC coverage: 91.415% (+0.009%) from 91.406%
15972967310

Pull #16009

github

web-flow
fix(vhelper): fix padding only when vhelper scrollbar is visible (#15972)
Pull Request #16009: Mass merging 20.0.x to master

13412 of 15747 branches covered (85.17%)

23 of 24 new or added lines in 2 files covered. (95.83%)

78 existing lines in 3 files now uncovered.

27111 of 29657 relevant lines covered (91.42%)

36664.17 hits per line

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

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

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

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

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

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

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

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

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

145

146
    /**
147
     * @hidden
148
     * @internal
149
     */
150
    protected get formGroup(): FormGroup {
151
        return this.grid.validation.getFormGroup(this.intRow.key);
5,822,562✔
152
    }
153

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

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

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

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

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

217
    @Input()
218
    public cellValidationErrorTemplate: TemplateRef<any>;
219

220
    @Input()
221
    public pinnedIndicator: TemplateRef<any>;
222

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

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

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

278
    /**
279
     * Gets the cell template.
280
     * ```typescript
281
     * let template = this.cell.template;
282
     * ```
283
     *
284
     * @memberof IgxGridCellComponent
285
     */
286
    public get template(): TemplateRef<any> {
287
        if (this.editMode && this.formGroup) {
323,430✔
288
            const inlineEditorTemplate = this.column.inlineEditorTemplate;
1,227✔
289
            return inlineEditorTemplate ? inlineEditorTemplate : this.inlineEditorTemplate;
1,227✔
290
        }
291
        if (this.cellTemplate) {
322,203✔
292
            return this.cellTemplate;
691✔
293
        }
294
        if (this.grid.rowEditable && this.intRow.addRowUI) {
321,512✔
295
            return this.addRowCellTemplate;
1,918✔
296
        }
297
        return this.defaultCellTemplate;
319,594✔
298
    }
299

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

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

327

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

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

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

367
    public set visibleColumnIndex(val) {
368
        this._vIndex = val;
158,497✔
369
    }
370

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

385
    @HostBinding('attr.id')
386
    public get attrCellID() {
387
        return `${this.intRow.gridID}_${this.rowIndex}_${this.visibleColumnIndex}`;
1,210,904✔
388
    }
389

390
    @HostBinding('attr.title')
391
    public get title() {
392
        if (this.editMode || this.cellTemplate || this.errorShowing) {
1,210,917✔
393
            return '';
5,231✔
394
        }
395

396
        if (this.formatter) {
1,205,686✔
397
            return this.formatter(this.value, this.rowData, this.columnData);
21,709✔
398
        }
399

400
        const args = this.column.pipeArgs;
1,183,977✔
401
        const locale = this.grid.locale;
1,183,977✔
402

403
        switch (this.column.dataType) {
1,183,977✔
404
            case GridColumnDataType.Percent:
405
                return formatPercent(this.value, locale, args.digitsInfo);
427✔
406
            case GridColumnDataType.Currency:
407
                return formatCurrency(this.value, this.currencyCode, args.display, args.digitsInfo, locale);
20,312✔
408
            case GridColumnDataType.Date:
409
            case GridColumnDataType.DateTime:
410
            case GridColumnDataType.Time:
411
                return formatDate(this.value, args.format, locale, args.timezone);
169,972✔
412
        }
413
        return this.value;
993,266✔
414
    }
415

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

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

433
    /**
434
     * @hidden
435
     * @internal
436
     */
437
    @Input()
438
    public get cellSelectionMode() {
439
        return this._cellSelection;
305,063✔
440
    }
441

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

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

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

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

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

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

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

517
    /** @hidden @internal */
518
    @HostBinding('attr.aria-describedby')
519
    public get ariaDescribeBy() {
520
        let describeBy = (this.gridID + '_' + this.column.field).replace('.', '_');
1,211,985✔
521
        if (this.isInvalid) {
1,211,985✔
522
            describeBy += ' ' + this.ariaErrorMessage;
107✔
523
        }
524
        return describeBy;
1,211,985✔
525
    }
526

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

532
    /**
533
     * @hidden
534
     * @internal
535
     */
536
    @HostBinding('class.igx-grid__td--invalid')
537
    @HostBinding('attr.aria-invalid')
538
    public get isInvalid() {
539
        const isInvalid = this.formGroup?.get(this.column?.field)?.invalid && this.formGroup?.get(this.column?.field)?.touched;
4,606,270✔
540
        return !this.intRow.deleted && isInvalid;
4,606,270✔
541
    }
542

543
    /**
544
     * @hidden
545
     * @internal
546
     */
547
    @HostBinding('class.igx-grid__td--valid')
548
    public get isValidAfterEdit() {
549
        const formControl = this.formGroup?.get(this.column?.field);
1,210,904✔
550
        return this.editMode && formControl && !formControl.invalid && formControl.dirty;
1,210,904✔
551
    }
552

553
    /**
554
     * Gets the formControl responsible for value changes and validation for this cell.
555
     */
556
    protected get formControl(): FormControl {
557
        return this.grid.validation.getFormControl(this.intRow.key, this.column.field) as FormControl;
5,040✔
558
    }
559

560
    public get gridRowSpan(): number {
561
        return this.column.gridRowSpan;
198✔
562
    }
563

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

568
    public get rowEnd(): number {
569
        return this.column.rowEnd;
×
570
    }
571

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

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

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

584
    /**
585
     * Gets the width of the cell.
586
     * ```typescript
587
     * let cellWidth = this.cell.width;
588
     * ```
589
     *
590
     * @memberof IgxGridCellComponent
591
     */
592
    @Input()
593
    public width = '';
152,023✔
594

595
    /**
596
     * @hidden
597
     */
598
    @Input()
599
    @HostBinding('class.igx-grid__td--active')
600
    public active = false;
152,023✔
601

602
    @HostBinding('attr.aria-selected')
603
    public get ariaSelected() {
604
        return this.selected || this.column.selected || this.intRow.selected;
1,210,904✔
605
    }
606

607
    /**
608
     * Gets whether the cell is selected.
609
     * ```typescript
610
     * let isSelected = this.cell.selected;
611
     * ```
612
     *
613
     * @memberof IgxGridCellComponent
614
     */
615
    @HostBinding('class.igx-grid__td--selected')
616
    public get selected() {
617
        return this.selectionService.selected(this.selectionNode);
2,423,893✔
618
    }
619

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

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

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

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

681
    /**
682
     * Returns whether the cell is editable.
683
     */
684
    public get editable(): boolean {
685
        return this.column.editable && !this.intRow.disabled;
1,212,170✔
686
    }
687

688
    /**
689
     * @hidden
690
     */
691
    @Input()
692
    @HostBinding('class.igx-grid__td--row-pinned-first')
693
    public displayPinnedChip = false;
152,023✔
694

695
    @HostBinding('style.min-height.px')
696
    protected get minHeight() {
697
        if ((this.grid as any).isCustomSetRowHeight) {
1,210,904✔
698
            return this.grid.renderedRowHeight;
464✔
699
        }
700
    }
701

702
    @ViewChild('defaultCell', { read: TemplateRef, static: true })
703
    protected defaultCellTemplate: TemplateRef<any>;
704

705
    @ViewChild('defaultPinnedIndicator', { read: TemplateRef, static: true })
706
    protected defaultPinnedIndicator: TemplateRef<any>;
707

708
    @ViewChild('inlineEditor', { read: TemplateRef, static: true })
709
    protected inlineEditorTemplate: TemplateRef<any>;
710

711
    @ViewChild('addRowCell', { read: TemplateRef, static: true })
712
    protected addRowCellTemplate: TemplateRef<any>;
713

714
    @ViewChild(IgxTextHighlightDirective, { read: IgxTextHighlightDirective })
715
    protected set highlight(value: IgxTextHighlightDirective) {
716
        this._highlight = value;
154,047✔
717

718
        if (this._highlight && this.grid.lastSearchInfo.searchText) {
154,047✔
719
            this._highlight.highlight(this.grid.lastSearchInfo.searchText,
399✔
720
                this.grid.lastSearchInfo.caseSensitive,
721
                this.grid.lastSearchInfo.exactMatch);
722
            this._highlight.activateIfNecessary();
399✔
723
        }
724
    }
725

726
    protected get highlight() {
727
        return this._highlight;
352,599✔
728
    }
729

730
    protected get selectionNode(): ISelectionNode {
731
        return {
2,425,770✔
732
            row: this.rowIndex,
733
            column: this.column.columnLayoutChild ? this.column.parent.visibleIndex : this.visibleColumnIndex,
2,425,770✔
734
            layout: this.column.columnLayoutChild ? {
2,425,770✔
735
                rowStart: this.column.rowStart,
736
                colStart: this.column.colStart,
737
                rowEnd: this.column.rowEnd,
738
                colEnd: this.column.colEnd,
739
                columnVisibleIndex: this.visibleColumnIndex
740
            } : null
741
        };
742
    }
743

744
    /**
745
     * Sets/gets the highlight class of the cell.
746
     * Default value is `"igx-highlight"`.
747
     * ```typescript
748
     * let highlightClass = this.cell.highlightClass;
749
     * ```
750
     * ```typescript
751
     * this.cell.highlightClass = 'igx-cell-highlight';
752
     * ```
753
     *
754
     * @memberof IgxGridCellComponent
755
     */
756
    public highlightClass = 'igx-highlight';
152,023✔
757

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

772
    /** @hidden @internal */
773
    public get step(): number {
774
        const digitsInfo = this.column.pipeArgs.digitsInfo;
218✔
775
        if (!digitsInfo) {
218!
776
            return 1;
×
777
        }
778
        const step = +digitsInfo.substr(digitsInfo.indexOf('.') + 1, 1);
218✔
779
        return 1 / (Math.pow(10, step));
218✔
780
    }
781

782
    /** @hidden @internal */
783
    public get currencyCode(): string {
784
        return this.column.pipeArgs.currencyCode ?
57,172✔
785
            this.column.pipeArgs.currencyCode : getLocaleCurrencyCode(this.grid.locale);
786
    }
787

788
    /** @hidden @internal */
789
    public get currencyCodeSymbol(): string {
790
        return getCurrencySymbol(this.currencyCode, 'wide', this.grid.locale);
4✔
791
    }
792

793
    protected _lastSearchInfo: ISearchInfo;
794
    private _highlight: IgxTextHighlightDirective;
795
    private _cellSelection: GridSelectionMode = GridSelectionMode.multiple;
152,023✔
796
    private _vIndex = -1;
152,023✔
797

798
    constructor(
799
        protected selectionService: IgxGridSelectionService,
152,023✔
800
        @Inject(IGX_GRID_BASE) public grid: GridType,
152,023✔
801
        @Inject(IgxOverlayService) protected overlayService: IgxOverlayService,
152,023✔
802
        public cdr: ChangeDetectorRef,
152,023✔
803
        private element: ElementRef<HTMLElement>,
152,023✔
804
        protected zone: NgZone,
152,023✔
805
        private touchManager: HammerGesturesManager,
152,023✔
806
        protected platformUtil: PlatformUtil
152,023✔
807
    ) { }
808

809
    /**
810
     * @hidden
811
     * @internal
812
     */
813
    @HostListener('dblclick', ['$event'])
814
    public onDoubleClick = (event: MouseEvent) => {
152,023✔
815
        if (event.type === 'doubletap') {
150✔
816
            // prevent double-tap to zoom on iOS
817
            event.preventDefault();
1✔
818
        }
819
        if (this.editable && !this.editMode && !this.intRow.deleted && !this.grid.crudService.rowEditingBlocked) {
150✔
820
            this.grid.crudService.enterEditMode(this, event as Event);
144✔
821
        }
822

823
        this.grid.doubleClick.emit({
150✔
824
            cell: this.getCellType(),
825
            event
826
        });
827
    };
828

829
    /**
830
     * @hidden
831
     * @internal
832
     */
833
    @HostListener('click', ['$event'])
834
    public onClick(event: MouseEvent) {
835
        this.grid.cellClick.emit({
260✔
836
            cell: this.getCellType(),
837
            event
838
        });
839
    }
840

841
    /**
842
     * @hidden
843
     * @internal
844
     */
845
    public ngOnInit() {
846
        this.zone.runOutsideAngular(() => {
152,023✔
847
            this.nativeElement.addEventListener('pointerdown', this.pointerdown);
152,023✔
848
            this.addPointerListeners(this.cellSelectionMode);
152,023✔
849
        });
850
        if (this.platformUtil.isIOS) {
152,023✔
851
            this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
40✔
852
                cssProps: {} /* don't disable user-select, etc */
853
            });
854
        }
855

856
    }
857

858
    public ngAfterViewInit() {
859
        this.errorTooltip.changes.pipe(takeUntil(this._destroy$)).subscribe(() => {
152,023✔
860
            if (this.errorTooltip.length > 0 && this.active) {
43✔
861
                // error ocurred
862
                this.cdr.detectChanges();
24✔
863
                this.openErrorTooltip();
24✔
864
            }
865
        });
866
    }
867

868
    /**
869
     * @hidden
870
     * @internal
871
     */
872
    public errorShowing = false;
152,023✔
873

874
    private openErrorTooltip() {
875
        const tooltip = this.errorTooltip.first;
25✔
876
        tooltip.open(
25✔
877
            {
878
                target: this.errorIcon.el.nativeElement,
879
                closeOnOutsideClick: true,
880
                excludeFromOutsideClick: [this.nativeElement],
881
                closeOnEscape: false,
882
                outlet: this.grid.outlet,
883
                modal: false,
884
                positionStrategy: new AutoPositionStrategy({
885
                    horizontalStartPoint: HorizontalAlignment.Center,
886
                    horizontalDirection: HorizontalAlignment.Center
887
                })
888
            }
889
        );
890
    }
891

892
    /**
893
     * @hidden
894
     * @internal
895
     */
896
    public ngOnDestroy() {
897
        this.zone.runOutsideAngular(() => {
150,678✔
898
            this.nativeElement.removeEventListener('pointerdown', this.pointerdown);
150,678✔
899
            this.removePointerListeners(this.cellSelectionMode);
150,678✔
900
        });
901
        this.touchManager.destroy();
150,678✔
902
        this._destroy$.next();
150,678✔
903
        this._destroy$.complete();
150,678✔
904
    }
905

906
    /**
907
     * @hidden
908
     * @internal
909
     */
910
    public ngOnChanges(changes: SimpleChanges): void {
911
        if (changes.editMode && changes.editMode.currentValue && this.formControl) {
290,041✔
912
            // ensure when values change, form control is forced to be marked as touche.
913
            this.formControl.valueChanges.pipe(takeWhile(() => this.editMode)).subscribe(() => this.formControl.markAsTouched());
397✔
914
            // while in edit mode subscribe to value changes on the current form control and set to editValue
915
            this.formControl.statusChanges.pipe(takeWhile(() => this.editMode)).subscribe(status => {
397✔
916
                if (status === 'INVALID' && this.errorTooltip.length > 0) {
189!
917
                    this.cdr.detectChanges();
×
918
                    const tooltip = this.errorTooltip.first;
×
919
                    this.resizeAndRepositionOverlayById(tooltip.overlayId, this.errorTooltip.first.element.offsetWidth);
×
920
                }
921
            });
922
        }
923
        if (changes.value && !changes.value.firstChange) {
290,041✔
924
            if (this.highlight) {
47,739✔
925
                this.highlight.lastSearchInfo.searchText = this.grid.lastSearchInfo.searchText;
45,345✔
926
                this.highlight.lastSearchInfo.caseSensitive = this.grid.lastSearchInfo.caseSensitive;
45,345✔
927
                this.highlight.lastSearchInfo.exactMatch = this.grid.lastSearchInfo.exactMatch;
45,345✔
928
            }
929
        }
930
    }
931

932

933

934
    /**
935
     * @hidden @internal
936
     */
937
    private resizeAndRepositionOverlayById(overlayId: string, newSize: number) {
UNCOV
938
        const overlay = this.overlayService.getOverlayById(overlayId);
×
UNCOV
939
        if (!overlay) return;
×
UNCOV
940
        overlay.initialSize.width = newSize;
×
UNCOV
941
        overlay.elementRef.nativeElement.parentElement.style.width = newSize + 'px';
×
942
        this.overlayService.reposition(overlayId);
×
943
    }
944

945
    /**
946
     * Starts/ends edit mode for the cell.
947
     *
948
     * ```typescript
949
     * cell.setEditMode(true);
950
     * ```
951
     */
952
    public setEditMode(value: boolean): void {
953
        if (this.intRow.deleted) {
30!
UNCOV
954
            return;
×
955
        }
956
        if (this.editable && value) {
30✔
957
            if (this.grid.crudService.cellInEditMode) {
26✔
958
                this.grid.gridAPI.update_cell(this.grid.crudService.cell);
5✔
959
                this.grid.crudService.endCellEdit();
5✔
960
            }
961
            this.grid.crudService.enterEditMode(this);
26✔
962
        } else {
963
            this.grid.crudService.endCellEdit();
4✔
964
        }
965
        this.grid.notifyChanges();
30✔
966
    }
967

968
    /**
969
     * Sets new value to the cell.
970
     * ```typescript
971
     * this.cell.update('New Value');
972
     * ```
973
     *
974
     * @memberof IgxGridCellComponent
975
     */
976
    // TODO: Refactor
977
    public update(val: any) {
978
        if (this.intRow.deleted) {
33!
UNCOV
979
            return;
×
980
        }
981

982
        let cell = this.grid.crudService.cell;
33✔
983
        if (!cell) {
33✔
984
            cell = this.grid.crudService.createCell(this);
14✔
985
        }
986
        cell.editValue = val;
33✔
987
        this.grid.gridAPI.update_cell(cell);
33✔
988
        this.grid.crudService.endCellEdit();
33✔
989
        this.cdr.markForCheck();
33✔
990
    }
991

992
    /**
993
     *
994
     * @hidden
995
     * @internal
996
     */
997
    public pointerdown = (event: PointerEvent) => {
152,023✔
998
        if (this.cellSelectionMode !== GridSelectionMode.multiple) {
424✔
999
            this.activate(event);
23✔
1000
            return;
23✔
1001
        }
1002
        if (!this.platformUtil.isLeftClick(event)) {
401✔
1003
            event.preventDefault();
4✔
1004
            this.grid.navigation.setActiveNode({ rowIndex: this.rowIndex, colIndex: this.visibleColumnIndex });
4✔
1005
            this.selectionService.addKeyboardRange();
4✔
1006
            this.selectionService.initKeyboardState();
4✔
1007
            this.selectionService.primaryButton = false;
4✔
1008
            // Ensure RMB Click on edited cell does not end cell editing
1009
            if (!this.selected) {
4✔
1010
                this.grid.crudService.updateCell(true, event);
2✔
1011
            }
1012
            return;
4✔
1013
        } else {
1014
            this.selectionService.primaryButton = true;
397✔
1015
        }
1016
        this.selectionService.pointerDown(this.selectionNode, event.shiftKey, event.ctrlKey);
397✔
1017
        this.activate(event);
397✔
1018
    };
1019

1020
    /**
1021
     *
1022
     * @hidden
1023
     * @internal
1024
     */
1025
    public pointerenter = (event: PointerEvent) => {
152,023✔
1026
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
118✔
1027
        if (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID || this.grid.navigation.activeNode.gridID !== this.gridID)) {
118✔
1028
            return;
3✔
1029
        }
1030
        const dragMode = this.selectionService.pointerEnter(this.selectionNode, event);
115✔
1031
        if (dragMode) {
115✔
1032
            this.grid.cdr.detectChanges();
114✔
1033
        }
1034
    };
1035

1036
    /**
1037
     * @hidden
1038
     * @internal
1039
     */
1040
    public focusout = () => {
152,023✔
1041
        this.closeErrorTooltip();
48✔
1042
    }
1043

1044
    private closeErrorTooltip() {
1045
        const tooltip = this.errorTooltip.first;
48✔
1046
        if (tooltip) {
48!
UNCOV
1047
            tooltip.close();
×
1048
        }
1049
    }
1050

1051
    /**
1052
     * @hidden
1053
     * @internal
1054
     */
1055
    public pointerup = (event: PointerEvent) => {
152,023✔
1056
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
398✔
1057
        if (!this.platformUtil.isLeftClick(event) || (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID ||
398✔
1058
            this.grid.navigation.activeNode.gridID !== this.gridID))) {
1059
            return;
4✔
1060
        }
1061
        if (this.selectionService.pointerUp(this.selectionNode, this.grid.rangeSelected)) {
394✔
1062
            this.grid.cdr.detectChanges();
49✔
1063
        }
1064
    };
1065

1066
    /**
1067
     * @hidden
1068
     * @internal
1069
     */
1070
    public activate(event: FocusEvent | KeyboardEvent) {
1071
        const node = this.selectionNode;
970✔
1072
        let shouldEmitSelection = !this.selectionService.isActiveNode(node);
970✔
1073

1074
        if (this.selectionService.primaryButton) {
970!
1075
            const currentActive = this.selectionService.activeElement;
970✔
1076
            if (this.cellSelectionMode === GridSelectionMode.single && (event as any)?.ctrlKey && this.selected) {
970✔
1077
                this.selectionService.activeElement = null;
1✔
1078
                shouldEmitSelection = true;
1✔
1079
            } else {
1080
                this.selectionService.activeElement = node;
969✔
1081
            }
1082
            const cancel = this._updateCRUDStatus(event);
970✔
1083
            if (cancel) {
970✔
1084
                this.selectionService.activeElement = currentActive;
2✔
1085
                return;
2✔
1086
            }
1087

1088
            const activeElement = this.selectionService.activeElement;
968✔
1089
            const row = activeElement ? this.grid.gridAPI.get_row_by_index(activeElement.row) : null;
968✔
1090
            if (this.grid.crudService.rowEditingBlocked && row && this.intRow.key !== row.key) {
968!
UNCOV
1091
                return;
×
1092
            }
1093

1094
        } else {
1095
            this.selectionService.activeElement = null;
×
UNCOV
1096
            if (this.grid.crudService.cellInEditMode && !this.editMode) {
×
UNCOV
1097
                this.grid.crudService.updateCell(true, event);
×
1098
            }
1099
        }
1100

1101
        this.grid.navigation.setActiveNode({ row: this.rowIndex, column: this.visibleColumnIndex });
968✔
1102

1103
        const isTargetErrorIcon = event && event.target && event.target === this.errorIcon?.el.nativeElement
968✔
1104
        if (this.isInvalid && !isTargetErrorIcon) {
968✔
1105
            this.cdr.detectChanges();
1✔
1106
            this.openErrorTooltip();
1✔
1107
            this.grid.activeNodeChange.pipe(first()).subscribe(() => {
1✔
UNCOV
1108
                this.closeErrorTooltip();
×
1109
            });
1110
        }
1111
        this.selectionService.primaryButton = true;
968✔
1112
        if (this.cellSelectionMode === GridSelectionMode.multiple && this.selectionService.activeElement) {
968✔
1113
            if (this.selectionService.isInMap(this.selectionService.activeElement) && (event as any)?.ctrlKey && !(event as any)?.shiftKey) {
936✔
1114
                this.selectionService.remove(this.selectionService.activeElement);
3✔
1115
                shouldEmitSelection = true;
3✔
1116
            } else {
1117
                this.selectionService.add(this.selectionService.activeElement, false); // pointer events handle range generation
933✔
1118
                this.selectionService.keyboardStateOnFocus(node, this.grid.rangeSelected, this.nativeElement);
933✔
1119
            }
1120
        }
1121
        if (this.grid.isCellSelectable && shouldEmitSelection) {
968✔
1122
            this.zone.run(() => this.grid.selected.emit({ cell: this.getCellType(), event }));
941✔
1123
        }
1124
    }
1125

1126
    /**
1127
     * If the provided string matches the text in the cell, the text gets highlighted.
1128
     * ```typescript
1129
     * this.cell.highlightText('Cell Value', true);
1130
     * ```
1131
     *
1132
     * @memberof IgxGridCellComponent
1133
     */
1134
    public highlightText(text: string, caseSensitive?: boolean, exactMatch?: boolean): number {
1135
        return this.highlight && this.column.searchable ? this.highlight.highlight(text, caseSensitive, exactMatch) : 0;
160,420✔
1136
    }
1137

1138
    /**
1139
     * Clears the highlight of the text in the cell.
1140
     * ```typescript
1141
     * this.cell.clearHighLight();
1142
     * ```
1143
     *
1144
     * @memberof IgxGridCellComponent
1145
     */
1146
    public clearHighlight() {
1147
        if (this.highlight && this.column.searchable) {
40✔
1148
            this.highlight.clearHighlight();
40✔
1149
        }
1150
    }
1151

1152
    /**
1153
     * @hidden
1154
     * @internal
1155
     */
1156
    public calculateSizeToFit(range: any): number {
1157
        return this.platformUtil.getNodeSizeViaRange(range, this.nativeElement);
214✔
1158
    }
1159

1160
    /**
1161
     * @hidden
1162
     * @internal
1163
     */
1164
    public get searchMetadata() {
1165
        const meta = new Map<string, any>();
302,323✔
1166
        meta.set('pinned', this.grid.isRecordPinnedByViewIndex(this.intRow.index));
302,323✔
1167
        return meta;
302,323✔
1168
    }
1169

1170
    /**
1171
     * @hidden
1172
     * @internal
1173
     */
1174
    private _updateCRUDStatus(event?: Event) {
1175
        if (this.editMode) {
970✔
1176
            return;
48✔
1177
        }
1178

1179
        let editableArgs;
1180
        const crud = this.grid.crudService;
922✔
1181
        const editableCell = this.grid.crudService.cell;
922✔
1182
        const editMode = !!(crud.row || crud.cell);
922✔
1183

1184
        if (this.editable && editMode && !this.intRow.deleted) {
922✔
1185
            if (editableCell) {
88✔
1186
                editableArgs = this.grid.crudService.updateCell(false, event);
77✔
1187

1188
                /* This check is related with the following issue #6517:
1189
                 * when edit cell that belongs to a column which is sorted and press tab,
1190
                 * the next cell in edit mode is with wrong value /its context is not updated/;
1191
                 * So we reapply sorting before the next cell enters edit mode.
1192
                 * Also we need to keep the notifyChanges below, because of the current
1193
                 * change detection cycle when we have editing with enabled transactions
1194
                 */
1195
                if (this.grid.sortingExpressions.length && this.grid.sortingExpressions.indexOf(editableCell.column.field)) {
77!
UNCOV
1196
                    this.grid.cdr.detectChanges();
×
1197
                }
1198

1199
                if (editableArgs && editableArgs.cancel) {
77✔
1200
                    return true;
2✔
1201
                }
1202

1203
                crud.exitCellEdit(event);
75✔
1204
            }
1205
            this.grid.tbody.nativeElement.focus({ preventScroll: true });
86✔
1206
            this.grid.notifyChanges();
86✔
1207
            crud.enterEditMode(this, event);
86✔
1208
            return false;
86✔
1209
        }
1210

1211
        if (editableCell && crud.sameRow(this.cellID.rowID)) {
834✔
1212
            this.grid.crudService.updateCell(true, event);
1✔
1213
        } else if (editMode && !crud.sameRow(this.cellID.rowID)) {
833✔
1214
            this.grid.crudService.endEdit(true, event);
3✔
1215
        }
1216
    }
1217

1218
    private addPointerListeners(selection) {
1219
        if (selection !== GridSelectionMode.multiple) {
152,083✔
1220
            return;
604✔
1221
        }
1222
        this.nativeElement.addEventListener('pointerenter', this.pointerenter);
151,479✔
1223
        this.nativeElement.addEventListener('pointerup', this.pointerup);
151,479✔
1224
        this.nativeElement.addEventListener('focusout', this.focusout);
151,479✔
1225
    }
1226

1227
    private removePointerListeners(selection) {
1228
        if (selection !== GridSelectionMode.multiple) {
151,590✔
1229
            return;
852✔
1230
        }
1231
        this.nativeElement.removeEventListener('pointerenter', this.pointerenter);
150,738✔
1232
        this.nativeElement.removeEventListener('pointerup', this.pointerup);
150,738✔
1233
        this.nativeElement.removeEventListener('focusout', this.focusout);
150,738✔
1234
    }
1235

1236
    private getCellType(useRow?: boolean): CellType {
1237
        const rowID = useRow ? this.grid.createRow(this.intRow.index, this.intRow.data) : this.intRow.index;
3,349✔
1238
        return new IgxGridCell(this.grid, rowID, this.column);
3,349✔
1239
    }
1240
}
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