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

IgniteUI / igniteui-angular / 16621130295

30 Jul 2025 11:20AM UTC coverage: 91.358% (-0.05%) from 91.41%
16621130295

Pull #16024

github

web-flow
Merge bcae71b27 into 160626d2e
Pull Request #16024: Grid Cell merging

13547 of 15926 branches covered (85.06%)

197 of 217 new or added lines in 10 files covered. (90.78%)

14 existing lines in 1 file now uncovered.

27315 of 29899 relevant lines covered (91.36%)

37847.21 hits per line

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

344

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

549
    /**
550
     * @hidden
551
     * @internal
552
     */
553
    @HostBinding('class.igx-grid__td--invalid')
554
    @HostBinding('attr.aria-invalid')
555
    public get isInvalid() {
556
        const isInvalid = this.formGroup?.get(this.column?.field)?.invalid && this.formGroup?.get(this.column?.field)?.touched;
4,641,483✔
557
        return !this.intRow.deleted && isInvalid;
4,641,483✔
558
    }
559

560
    /**
561
     * @hidden
562
     * @internal
563
     */
564
    @HostBinding('class.igx-grid__td--valid')
565
    public get isValidAfterEdit() {
566
        const formControl = this.formGroup?.get(this.column?.field);
1,218,859✔
567
        return this.editMode && formControl && !formControl.invalid && formControl.dirty;
1,218,859✔
568
    }
569

570
    /**
571
     * Gets the formControl responsible for value changes and validation for this cell.
572
     */
573
    protected get formControl(): FormControl {
574
        return this.grid.validation.getFormControl(this.intRow.key, this.column.field) as FormControl;
54,392✔
575
    }
576

577
    public get gridRowSpan(): number {
578
        return this.column.gridRowSpan;
198✔
579
    }
580

581
    public get gridColumnSpan(): number {
582
        return this.column.gridColumnSpan;
198✔
583
    }
584

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

589
    public get colEnd(): number {
590
        return this.column.colEnd;
×
591
    }
592

593
    public get rowStart(): number {
594
        return this.column.rowStart;
×
595
    }
596

597
    public get colStart(): number {
598
        return this.column.colStart;
×
599
    }
600

601
    /**
602
     * Gets the width of the cell.
603
     * ```typescript
604
     * let cellWidth = this.cell.width;
605
     * ```
606
     *
607
     * @memberof IgxGridCellComponent
608
     */
609
    @Input()
610
    public width = '';
154,411✔
611

612
    /**
613
     * @hidden
614
     */
615
    @Input()
616
    @HostBinding('class.igx-grid__td--active')
617
    public active = false;
154,411✔
618

619
    @HostBinding('attr.aria-selected')
620
    public get ariaSelected() {
621
        return this.selected || this.column.selected || this.intRow.selected;
1,218,859✔
622
    }
623

624
    /**
625
     * Gets whether the cell is selected.
626
     * ```typescript
627
     * let isSelected = this.cell.selected;
628
     * ```
629
     *
630
     * @memberof IgxGridCellComponent
631
     */
632
    @HostBinding('class.igx-grid__td--selected')
633
    public get selected() {
634
        return this.selectionService.selected(this.selectionNode);
2,439,803✔
635
    }
636

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

655
    /**
656
     * Gets whether the cell column is selected.
657
     * ```typescript
658
     * let isCellColumnSelected = this.cell.columnSelected;
659
     * ```
660
     *
661
     * @memberof IgxGridCellComponent
662
     */
663
    @HostBinding('class.igx-grid__td--column-selected')
664
    public get columnSelected() {
665
        return this.selectionService.isColumnSelected(this.column.field);
1,218,859✔
666
    }
667

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

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

698
    /**
699
     * Returns whether the cell is editable.
700
     */
701
    public get editable(): boolean {
702
        return this.column.editable && !this.intRow.disabled;
1,220,133✔
703
    }
704

705
    /**
706
     * @hidden
707
     */
708
    @Input()
709
    @HostBinding('class.igx-grid__td--row-pinned-first')
710
    public displayPinnedChip = false;
154,411✔
711

712
    @HostBinding('style.min-height.px')
713
    protected get minHeight() {
714
        if ((this.grid as any).isCustomSetRowHeight) {
1,218,859✔
715
            return this.grid.renderedRowHeight;
464✔
716
        }
717
    }
718

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

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

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

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

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

734
    @ViewChild(IgxTextHighlightDirective, { read: IgxTextHighlightDirective })
735
    protected set highlight(value: IgxTextHighlightDirective) {
736
        this._highlight = value;
156,540✔
737

738
        if (this._highlight && this.grid.lastSearchInfo.searchText) {
156,540✔
739
            this._highlight.highlight(this.grid.lastSearchInfo.searchText,
400✔
740
                this.grid.lastSearchInfo.caseSensitive,
741
                this.grid.lastSearchInfo.exactMatch);
742
            this._highlight.activateIfNecessary();
400✔
743
        }
744
    }
745

746
    protected get highlight() {
747
        return this._highlight;
356,049✔
748
    }
749

750
    protected get selectionNode(): ISelectionNode {
751
        return {
2,441,696✔
752
            row: this.rowIndex,
753
            column: this.column.columnLayoutChild ? this.column.parent.visibleIndex : this.visibleColumnIndex,
2,441,696✔
754
            layout: this.column.columnLayoutChild ? {
2,441,696✔
755
                rowStart: this.column.rowStart,
756
                colStart: this.column.colStart,
757
                rowEnd: this.column.rowEnd,
758
                colEnd: this.column.colEnd,
759
                columnVisibleIndex: this.visibleColumnIndex
760
            } : null
761
        };
762
    }
763

764
    /**
765
     * Sets/gets the highlight class of the cell.
766
     * Default value is `"igx-highlight"`.
767
     * ```typescript
768
     * let highlightClass = this.cell.highlightClass;
769
     * ```
770
     * ```typescript
771
     * this.cell.highlightClass = 'igx-cell-highlight';
772
     * ```
773
     *
774
     * @memberof IgxGridCellComponent
775
     */
776
    public highlightClass = 'igx-highlight';
154,411✔
777

778
    /**
779
     * Sets/gets the active highlight class class of the cell.
780
     * Default value is `"igx-highlight__active"`.
781
     * ```typescript
782
     * let activeHighlightClass = this.cell.activeHighlightClass;
783
     * ```
784
     * ```typescript
785
     * this.cell.activeHighlightClass = 'igx-cell-highlight_active';
786
     * ```
787
     *
788
     * @memberof IgxGridCellComponent
789
     */
790
    public activeHighlightClass = 'igx-highlight__active';
154,411✔
791

792
    /** @hidden @internal */
793
    public get step(): number {
794
        const digitsInfo = this.column.pipeArgs.digitsInfo;
214✔
795
        if (!digitsInfo) {
214!
796
            return 1;
×
797
        }
798
        const step = +digitsInfo.substr(digitsInfo.indexOf('.') + 1, 1);
214✔
799
        return 1 / (Math.pow(10, step));
214✔
800
    }
801

802
    /** @hidden @internal */
803
    public get currencyCode(): string {
804
        return this.column.pipeArgs.currencyCode ?
57,180✔
805
            this.column.pipeArgs.currencyCode : getLocaleCurrencyCode(this.grid.locale);
806
    }
807

808
    /** @hidden @internal */
809
    public get currencyCodeSymbol(): string {
810
        return getCurrencySymbol(this.currencyCode, 'wide', this.grid.locale);
4✔
811
    }
812

813
    protected _lastSearchInfo: ISearchInfo;
814
    private _highlight: IgxTextHighlightDirective;
815
    private _cellSelection: GridSelectionMode = GridSelectionMode.multiple;
154,411✔
816
    private _vIndex = -1;
154,411✔
817

818
    constructor(
819
        protected selectionService: IgxGridSelectionService,
154,411✔
820
        @Inject(IGX_GRID_BASE) public grid: GridType,
154,411✔
821
        @Inject(IgxOverlayService) protected overlayService: IgxOverlayService,
154,411✔
822
        public cdr: ChangeDetectorRef,
154,411✔
823
        private element: ElementRef<HTMLElement>,
154,411✔
824
        protected zone: NgZone,
154,411✔
825
        private touchManager: HammerGesturesManager,
154,411✔
826
        protected platformUtil: PlatformUtil
154,411✔
827
    ) { }
828

829
    /**
830
     * @hidden
831
     * @internal
832
     */
833
    @HostListener('dblclick', ['$event'])
834
    public onDoubleClick = (event: MouseEvent) => {
154,411✔
835
        if (event.type === 'doubletap') {
152✔
836
            // prevent double-tap to zoom on iOS
837
            event.preventDefault();
1✔
838
        }
839
        if (this.editable && !this.editMode && !this.intRow.deleted && !this.grid.crudService.rowEditingBlocked) {
152✔
840
            this.grid.crudService.enterEditMode(this, event as Event);
146✔
841
        }
842

843
        this.grid.doubleClick.emit({
152✔
844
            cell: this.getCellType(),
845
            event
846
        });
847
    };
848

849
    /**
850
     * @hidden
851
     * @internal
852
     */
853
    @HostListener('click', ['$event'])
854
    public onClick(event: MouseEvent) {
855
        this.grid.cellClick.emit({
262✔
856
            cell: this.getCellType(),
857
            event
858
        });
859
    }
860

861
    /**
862
     * @hidden
863
     * @internal
864
     */
865
    public ngOnInit() {
866
        this.zone.runOutsideAngular(() => {
154,411✔
867
            this.nativeElement.addEventListener('pointerdown', this.pointerdown);
154,411✔
868
            this.addPointerListeners(this.cellSelectionMode);
154,411✔
869
        });
870
        if (this.platformUtil.isIOS) {
154,411✔
871
            this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
40✔
872
                cssProps: {} /* don't disable user-select, etc */
873
            });
874
        }
875

876
    }
877

878
    public ngAfterViewInit() {
879
        this.errorTooltip.changes.pipe(takeUntil(this._destroy$)).subscribe(() => {
154,411✔
880
            if (this.errorTooltip.length > 0 && this.active) {
43✔
881
                // error ocurred
882
                this.cdr.detectChanges();
24✔
883
                this.openErrorTooltip();
24✔
884
            }
885
        });
886
    }
887

888
    /**
889
     * @hidden
890
     * @internal
891
     */
892
    public errorShowing = false;
154,411✔
893

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

914
    /**
915
     * @hidden
916
     * @internal
917
     */
918
    public ngOnDestroy() {
919
        this.zone.runOutsideAngular(() => {
153,066✔
920
            this.nativeElement.removeEventListener('pointerdown', this.pointerdown);
153,066✔
921
            this.removePointerListeners(this.cellSelectionMode);
153,066✔
922
        });
923
        this.touchManager.destroy();
153,066✔
924
        this._destroy$.next();
153,066✔
925
        this._destroy$.complete();
153,066✔
926
    }
927

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

958

959

960
    /**
961
     * @hidden @internal
962
     */
963
    private resizeAndRepositionOverlayById(overlayId: string, newSize: number) {
964
        const overlay = this.overlayService.getOverlayById(overlayId);
×
965
        if (!overlay) return;
×
966
        overlay.initialSize.width = newSize;
×
967
        overlay.elementRef.nativeElement.parentElement.style.width = newSize + 'px';
×
968
        this.overlayService.reposition(overlayId);
×
969
    }
970

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

994
    /**
995
     * Sets new value to the cell.
996
     * ```typescript
997
     * this.cell.update('New Value');
998
     * ```
999
     *
1000
     * @memberof IgxGridCellComponent
1001
     */
1002
    // TODO: Refactor
1003
    public update(val: any) {
1004
        if (this.intRow.deleted) {
33!
1005
            return;
×
1006
        }
1007

1008
        let cell = this.grid.crudService.cell;
33✔
1009
        if (!cell) {
33✔
1010
            cell = this.grid.crudService.createCell(this);
14✔
1011
        }
1012
        cell.editValue = val;
33✔
1013
        this.grid.gridAPI.update_cell(cell);
33✔
1014
        this.grid.crudService.endCellEdit();
33✔
1015
        this.cdr.markForCheck();
33✔
1016
    }
1017

1018
    /**
1019
     *
1020
     * @hidden
1021
     * @internal
1022
     */
1023
    public pointerdown = (event: PointerEvent) => {
154,411✔
1024

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

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

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

1075
    /**
1076
     * @hidden
1077
     * @internal
1078
     */
1079
    public focusout = () => {
154,411✔
1080
        this.closeErrorTooltip();
49✔
1081
    }
1082

1083
    private closeErrorTooltip() {
1084
        const tooltip = this.errorTooltip.first;
49✔
1085
        if (tooltip) {
49!
1086
            tooltip.close();
×
1087
        }
1088
    }
1089

1090
    /**
1091
     * @hidden
1092
     * @internal
1093
     */
1094
    public pointerup = (event: PointerEvent) => {
154,411✔
1095
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
403✔
1096
        if (!this.platformUtil.isLeftClick(event) || (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID ||
403✔
1097
            this.grid.navigation.activeNode.gridID !== this.gridID))) {
1098
            return;
4✔
1099
        }
1100
        if (this.selectionService.pointerUp(this.selectionNode, this.grid.rangeSelected)) {
399✔
1101
            this.grid.cdr.detectChanges();
50✔
1102
        }
1103
    };
1104

1105
    /**
1106
     * @hidden
1107
     * @internal
1108
     */
1109
    public activate(event: FocusEvent | KeyboardEvent) {
1110
        const node = this.selectionNode;
975✔
1111
        let shouldEmitSelection = !this.selectionService.isActiveNode(node);
975✔
1112

1113
        if (this.selectionService.primaryButton) {
975!
1114
            const currentActive = this.selectionService.activeElement;
975✔
1115
            if (this.cellSelectionMode === GridSelectionMode.single && (event as any)?.ctrlKey && this.selected) {
975✔
1116
                this.selectionService.activeElement = null;
1✔
1117
                shouldEmitSelection = true;
1✔
1118
            } else {
1119
                this.selectionService.activeElement = node;
974✔
1120
            }
1121
            const cancel = this._updateCRUDStatus(event);
975✔
1122
            if (cancel) {
975✔
1123
                this.selectionService.activeElement = currentActive;
2✔
1124
                return;
2✔
1125
            }
1126

1127
            const activeElement = this.selectionService.activeElement;
973✔
1128
            const row = activeElement ? this.grid.gridAPI.get_row_by_index(activeElement.row) : null;
973✔
1129
            if (this.grid.crudService.rowEditingBlocked && row && this.intRow.key !== row.key) {
973!
1130
                return;
×
1131
            }
1132

1133
        } else {
1134
            this.selectionService.activeElement = null;
×
1135
            if (this.grid.crudService.cellInEditMode && !this.editMode) {
×
1136
                this.grid.crudService.updateCell(true, event);
×
1137
            }
1138
        }
1139

1140
        this.grid.navigation.setActiveNode({ row: this.rowIndex, column: this.visibleColumnIndex });
973✔
1141

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

1165
    /**
1166
     * If the provided string matches the text in the cell, the text gets highlighted.
1167
     * ```typescript
1168
     * this.cell.highlightText('Cell Value', true);
1169
     * ```
1170
     *
1171
     * @memberof IgxGridCellComponent
1172
     */
1173
    public highlightText(text: string, caseSensitive?: boolean, exactMatch?: boolean): number {
1174
        return this.highlight && this.column.searchable ? this.highlight.highlight(text, caseSensitive, exactMatch) : 0;
163,123✔
1175
    }
1176

1177
    /**
1178
     * Clears the highlight of the text in the cell.
1179
     * ```typescript
1180
     * this.cell.clearHighLight();
1181
     * ```
1182
     *
1183
     * @memberof IgxGridCellComponent
1184
     */
1185
    public clearHighlight() {
1186
        if (this.highlight && this.column.searchable) {
40✔
1187
            this.highlight.clearHighlight();
40✔
1188
        }
1189
    }
1190

1191
    /**
1192
     * @hidden
1193
     * @internal
1194
     */
1195
    public calculateSizeToFit(range: any): number {
1196
        return this.platformUtil.getNodeSizeViaRange(range, this.nativeElement);
214✔
1197
    }
1198

1199
    /**
1200
     * @hidden
1201
     * @internal
1202
     */
1203
    public get searchMetadata() {
1204
        const meta = new Map<string, any>();
305,286✔
1205
        meta.set('pinned', this.grid.isRecordPinnedByViewIndex(this.intRow.index));
305,286✔
1206
        return meta;
305,286✔
1207
    }
1208

1209
    /**
1210
     * @hidden
1211
     * @internal
1212
     */
1213
    private _updateCRUDStatus(event?: Event) {
1214
        if (this.editMode) {
975✔
1215
            return;
48✔
1216
        }
1217

1218
        let editableArgs;
1219
        const crud = this.grid.crudService;
927✔
1220
        const editableCell = this.grid.crudService.cell;
927✔
1221
        const editMode = !!(crud.row || crud.cell);
927✔
1222

1223
        if (this.editable && editMode && !this.intRow.deleted) {
927✔
1224
            if (editableCell) {
88✔
1225
                editableArgs = this.grid.crudService.updateCell(false, event);
77✔
1226

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

1238
                if (editableArgs && editableArgs.cancel) {
77✔
1239
                    return true;
2✔
1240
                }
1241

1242
                crud.exitCellEdit(event);
75✔
1243
            }
1244
            this.grid.tbody.nativeElement.focus({ preventScroll: true });
86✔
1245
            this.grid.notifyChanges();
86✔
1246
            crud.enterEditMode(this, event);
86✔
1247
            return false;
86✔
1248
        }
1249

1250
        if (editableCell && crud.sameRow(this.cellID.rowID)) {
839✔
1251
            this.grid.crudService.updateCell(true, event);
1✔
1252
        } else if (editMode && !crud.sameRow(this.cellID.rowID)) {
838✔
1253
            this.grid.crudService.endEdit(true, event);
3✔
1254
        }
1255
    }
1256

1257
    private addPointerListeners(selection) {
1258
        if (selection !== GridSelectionMode.multiple) {
154,471✔
1259
            return;
604✔
1260
        }
1261
        this.nativeElement.addEventListener('pointerenter', this.pointerenter);
153,867✔
1262
        this.nativeElement.addEventListener('pointerup', this.pointerup);
153,867✔
1263
        this.nativeElement.addEventListener('focusout', this.focusout);
153,867✔
1264
    }
1265

1266
    private removePointerListeners(selection) {
1267
        if (selection !== GridSelectionMode.multiple) {
153,978✔
1268
            return;
852✔
1269
        }
1270
        this.nativeElement.removeEventListener('pointerenter', this.pointerenter);
153,126✔
1271
        this.nativeElement.removeEventListener('pointerup', this.pointerup);
153,126✔
1272
        this.nativeElement.removeEventListener('focusout', this.focusout);
153,126✔
1273
    }
1274

1275
    private getCellType(useRow?: boolean): CellType {
1276
        const rowID = useRow ? this.grid.createRow(this.intRow.index, this.intRow.data) : this.intRow.index;
3,385✔
1277
        return new IgxGridCell(this.grid, rowID, this.column);
3,385✔
1278
    }
1279
}
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