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

IgniteUI / igniteui-angular / 16515177532

25 Jul 2025 06:13AM UTC coverage: 91.421%. First build
16515177532

Pull #16054

github

web-flow
Merge 8145c2013 into 0c1ad424c
Pull Request #16054: Handle validation for fields with '.' - 20.0.x

13444 of 15788 branches covered (85.15%)

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

27164 of 29713 relevant lines covered (91.42%)

34495.8 hits per line

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

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

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

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

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

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

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

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

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

147

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

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

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

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

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

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

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

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

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

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

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

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

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

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

329

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

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

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

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

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

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

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

398
        if (this.formatter) {
1,207,044✔
399
            return this.formatter(this.value, this.rowData, this.columnData);
22,032✔
400
        }
401

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

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

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

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

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

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

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

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

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

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

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

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

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

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

534
    /**
535
     * @hidden
536
     * @internal
537
     */
538
    @HostBinding('class.igx-grid__td--invalid')
539
    @HostBinding('attr.aria-invalid')
540
    public get isInvalid() {
541
        if (this.formGroup) {
4,612,989✔
542
            const isInvalid = this.grid.validation?.isFieldInvalid(this.formGroup, this.column?.field);
61,016✔
543
            return !this.intRow.deleted && isInvalid;
61,016✔
544
        }
545
        return false;
4,551,973✔
546
    }
547

548
    /**
549
     * @hidden
550
     * @internal
551
     */
552
    @HostBinding('class.igx-grid__td--valid')
553
    public get isValidAfterEdit() {
554
        if (this.formGroup) {
1,212,255✔
555
            const isValidAfterEdit = this.grid.validation?.isFieldValidAfterEdit(this.formGroup, this.column?.field);
11,070✔
556
            return this.editMode && isValidAfterEdit;
11,070✔
557
        }
558
        return false;
1,201,185✔
559
    }
560

561
    /**
562
     * Gets the formControl responsible for value changes and validation for this cell.
563
     */
564
    protected get formControl(): FormControl {
565
        return this.grid.validation.getFormControl(this.intRow.key, this.column.field) as FormControl;
54,331✔
566
    }
567

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

572
    public get gridColumnSpan(): number {
573
        return this.column.gridColumnSpan;
198✔
574
    }
575

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

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

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

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

592
    /**
593
     * Gets the width of the cell.
594
     * ```typescript
595
     * let cellWidth = this.cell.width;
596
     * ```
597
     *
598
     * @memberof IgxGridCellComponent
599
     */
600
    @Input()
601
    public width = '';
152,386✔
602

603
    /**
604
     * @hidden
605
     */
606
    @Input()
607
    @HostBinding('class.igx-grid__td--active')
608
    public active = false;
152,386✔
609

610
    @HostBinding('attr.aria-selected')
611
    public get ariaSelected() {
612
        return this.selected || this.column.selected || this.intRow.selected;
1,212,255✔
613
    }
614

615
    /**
616
     * Gets whether the cell is selected.
617
     * ```typescript
618
     * let isSelected = this.cell.selected;
619
     * ```
620
     *
621
     * @memberof IgxGridCellComponent
622
     */
623
    @HostBinding('class.igx-grid__td--selected')
624
    public get selected() {
625
        return this.selectionService.selected(this.selectionNode);
2,426,595✔
626
    }
627

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

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

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

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

689
    /**
690
     * Returns whether the cell is editable.
691
     */
692
    public get editable(): boolean {
693
        return this.column.editable && !this.intRow.disabled;
1,213,523✔
694
    }
695

696
    /**
697
     * @hidden
698
     */
699
    @Input()
700
    @HostBinding('class.igx-grid__td--row-pinned-first')
701
    public displayPinnedChip = false;
152,386✔
702

703
    @HostBinding('style.min-height.px')
704
    protected get minHeight() {
705
        if ((this.grid as any).isCustomSetRowHeight) {
1,212,255✔
706
            return this.grid.renderedRowHeight;
464✔
707
        }
708
    }
709

710
    @ViewChild('defaultCell', { read: TemplateRef, static: true })
711
    protected defaultCellTemplate: TemplateRef<any>;
712

713
    @ViewChild('defaultPinnedIndicator', { read: TemplateRef, static: true })
714
    protected defaultPinnedIndicator: TemplateRef<any>;
715

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

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

722
    @ViewChild(IgxTextHighlightDirective, { read: IgxTextHighlightDirective })
723
    protected set highlight(value: IgxTextHighlightDirective) {
724
        this._highlight = value;
154,419✔
725

726
        if (this._highlight && this.grid.lastSearchInfo.searchText) {
154,419✔
727
            this._highlight.highlight(this.grid.lastSearchInfo.searchText,
399✔
728
                this.grid.lastSearchInfo.caseSensitive,
729
                this.grid.lastSearchInfo.exactMatch);
730
            this._highlight.activateIfNecessary();
399✔
731
        }
732
    }
733

734
    protected get highlight() {
735
        return this._highlight;
352,853✔
736
    }
737

738
    protected get selectionNode(): ISelectionNode {
739
        return {
2,428,475✔
740
            row: this.rowIndex,
741
            column: this.column.columnLayoutChild ? this.column.parent.visibleIndex : this.visibleColumnIndex,
2,428,475✔
742
            layout: this.column.columnLayoutChild ? {
2,428,475✔
743
                rowStart: this.column.rowStart,
744
                colStart: this.column.colStart,
745
                rowEnd: this.column.rowEnd,
746
                colEnd: this.column.colEnd,
747
                columnVisibleIndex: this.visibleColumnIndex
748
            } : null
749
        };
750
    }
751

752
    /**
753
     * Sets/gets the highlight class of the cell.
754
     * Default value is `"igx-highlight"`.
755
     * ```typescript
756
     * let highlightClass = this.cell.highlightClass;
757
     * ```
758
     * ```typescript
759
     * this.cell.highlightClass = 'igx-cell-highlight';
760
     * ```
761
     *
762
     * @memberof IgxGridCellComponent
763
     */
764
    public highlightClass = 'igx-highlight';
152,386✔
765

766
    /**
767
     * Sets/gets the active highlight class class of the cell.
768
     * Default value is `"igx-highlight__active"`.
769
     * ```typescript
770
     * let activeHighlightClass = this.cell.activeHighlightClass;
771
     * ```
772
     * ```typescript
773
     * this.cell.activeHighlightClass = 'igx-cell-highlight_active';
774
     * ```
775
     *
776
     * @memberof IgxGridCellComponent
777
     */
778
    public activeHighlightClass = 'igx-highlight__active';
152,386✔
779

780
    /** @hidden @internal */
781
    public get step(): number {
782
        const digitsInfo = this.column.pipeArgs.digitsInfo;
218✔
783
        if (!digitsInfo) {
218!
784
            return 1;
×
785
        }
786
        const step = +digitsInfo.substr(digitsInfo.indexOf('.') + 1, 1);
218✔
787
        return 1 / (Math.pow(10, step));
218✔
788
    }
789

790
    /** @hidden @internal */
791
    public get currencyCode(): string {
792
        return this.column.pipeArgs.currencyCode ?
57,180✔
793
            this.column.pipeArgs.currencyCode : getLocaleCurrencyCode(this.grid.locale);
794
    }
795

796
    /** @hidden @internal */
797
    public get currencyCodeSymbol(): string {
798
        return getCurrencySymbol(this.currencyCode, 'wide', this.grid.locale);
4✔
799
    }
800

801
    protected _lastSearchInfo: ISearchInfo;
802
    private _highlight: IgxTextHighlightDirective;
803
    private _cellSelection: GridSelectionMode = GridSelectionMode.multiple;
152,386✔
804
    private _vIndex = -1;
152,386✔
805

806
    constructor(
807
        protected selectionService: IgxGridSelectionService,
152,386✔
808
        @Inject(IGX_GRID_BASE) public grid: GridType,
152,386✔
809
        @Inject(IgxOverlayService) protected overlayService: IgxOverlayService,
152,386✔
810
        public cdr: ChangeDetectorRef,
152,386✔
811
        private element: ElementRef<HTMLElement>,
152,386✔
812
        protected zone: NgZone,
152,386✔
813
        private touchManager: HammerGesturesManager,
152,386✔
814
        protected platformUtil: PlatformUtil
152,386✔
815
    ) { }
816

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

831
        this.grid.doubleClick.emit({
151✔
832
            cell: this.getCellType(),
833
            event
834
        });
835
    };
836

837
    /**
838
     * @hidden
839
     * @internal
840
     */
841
    @HostListener('click', ['$event'])
842
    public onClick(event: MouseEvent) {
843
        this.grid.cellClick.emit({
260✔
844
            cell: this.getCellType(),
845
            event
846
        });
847
    }
848

849
    /**
850
     * @hidden
851
     * @internal
852
     */
853
    public ngOnInit() {
854
        this.zone.runOutsideAngular(() => {
152,386✔
855
            this.nativeElement.addEventListener('pointerdown', this.pointerdown);
152,386✔
856
            this.addPointerListeners(this.cellSelectionMode);
152,386✔
857
        });
858
        if (this.platformUtil.isIOS) {
152,386✔
859
            this.touchManager.addEventListener(this.nativeElement, 'doubletap', this.onDoubleClick, {
40✔
860
                cssProps: {} /* don't disable user-select, etc */
861
            });
862
        }
863

864
    }
865

866
    public ngAfterViewInit() {
867
        this.errorTooltip.changes.pipe(takeUntil(this._destroy$)).subscribe(() => {
152,386✔
868
            if (this.errorTooltip.length > 0 && this.active) {
44✔
869
                // error ocurred
870
                this.cdr.detectChanges();
25✔
871
                this.openErrorTooltip();
25✔
872
            }
873
        });
874
    }
875

876
    /**
877
     * @hidden
878
     * @internal
879
     */
880
    public errorShowing = false;
152,386✔
881

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

902
    /**
903
     * @hidden
904
     * @internal
905
     */
906
    public ngOnDestroy() {
907
        this.zone.runOutsideAngular(() => {
151,041✔
908
            this.nativeElement.removeEventListener('pointerdown', this.pointerdown);
151,041✔
909
            this.removePointerListeners(this.cellSelectionMode);
151,041✔
910
        });
911
        this.touchManager.destroy();
151,041✔
912
        this._destroy$.next();
151,041✔
913
        this._destroy$.complete();
151,041✔
914
    }
915

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

946

947

948
    /**
949
     * @hidden @internal
950
     */
951
    private resizeAndRepositionOverlayById(overlayId: string, newSize: number) {
952
        const overlay = this.overlayService.getOverlayById(overlayId);
×
953
        if (!overlay) return;
×
954
        overlay.initialSize.width = newSize;
×
955
        overlay.elementRef.nativeElement.parentElement.style.width = newSize + 'px';
×
956
        this.overlayService.reposition(overlayId);
×
957
    }
958

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

982
    /**
983
     * Sets new value to the cell.
984
     * ```typescript
985
     * this.cell.update('New Value');
986
     * ```
987
     *
988
     * @memberof IgxGridCellComponent
989
     */
990
    // TODO: Refactor
991
    public update(val: any) {
992
        if (this.intRow.deleted) {
34!
993
            return;
×
994
        }
995

996
        let cell = this.grid.crudService.cell;
34✔
997
        if (!cell) {
34✔
998
            cell = this.grid.crudService.createCell(this);
14✔
999
        }
1000
        cell.editValue = val;
34✔
1001
        this.grid.gridAPI.update_cell(cell);
34✔
1002
        this.grid.crudService.endCellEdit();
34✔
1003
        this.cdr.markForCheck();
34✔
1004
    }
1005

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

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

1050
    /**
1051
     * @hidden
1052
     * @internal
1053
     */
1054
    public focusout = () => {
152,386✔
1055
        this.closeErrorTooltip();
48✔
1056
    }
1057

1058
    private closeErrorTooltip() {
1059
        const tooltip = this.errorTooltip.first;
48✔
1060
        if (tooltip) {
48!
1061
            tooltip.close();
×
1062
        }
1063
    }
1064

1065
    /**
1066
     * @hidden
1067
     * @internal
1068
     */
1069
    public pointerup = (event: PointerEvent) => {
152,386✔
1070
        const isHierarchicalGrid = this.grid.type === 'hierarchical';
399✔
1071
        if (!this.platformUtil.isLeftClick(event) || (isHierarchicalGrid && (!this.grid.navigation?.activeNode?.gridID ||
399✔
1072
            this.grid.navigation.activeNode.gridID !== this.gridID))) {
1073
            return;
4✔
1074
        }
1075
        if (this.selectionService.pointerUp(this.selectionNode, this.grid.rangeSelected)) {
395✔
1076
            this.grid.cdr.detectChanges();
49✔
1077
        }
1078
    };
1079

1080
    /**
1081
     * @hidden
1082
     * @internal
1083
     */
1084
    public activate(event: FocusEvent | KeyboardEvent) {
1085
        const node = this.selectionNode;
971✔
1086
        let shouldEmitSelection = !this.selectionService.isActiveNode(node);
971✔
1087

1088
        if (this.selectionService.primaryButton) {
971!
1089
            const currentActive = this.selectionService.activeElement;
971✔
1090
            if (this.cellSelectionMode === GridSelectionMode.single && (event as any)?.ctrlKey && this.selected) {
971✔
1091
                this.selectionService.activeElement = null;
1✔
1092
                shouldEmitSelection = true;
1✔
1093
            } else {
1094
                this.selectionService.activeElement = node;
970✔
1095
            }
1096
            const cancel = this._updateCRUDStatus(event);
971✔
1097
            if (cancel) {
971✔
1098
                this.selectionService.activeElement = currentActive;
2✔
1099
                return;
2✔
1100
            }
1101

1102
            const activeElement = this.selectionService.activeElement;
969✔
1103
            const row = activeElement ? this.grid.gridAPI.get_row_by_index(activeElement.row) : null;
969✔
1104
            if (this.grid.crudService.rowEditingBlocked && row && this.intRow.key !== row.key) {
969!
1105
                return;
×
1106
            }
1107

1108
        } else {
1109
            this.selectionService.activeElement = null;
×
1110
            if (this.grid.crudService.cellInEditMode && !this.editMode) {
×
1111
                this.grid.crudService.updateCell(true, event);
×
1112
            }
1113
        }
1114

1115
        this.grid.navigation.setActiveNode({ row: this.rowIndex, column: this.visibleColumnIndex });
969✔
1116

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

1140
    /**
1141
     * If the provided string matches the text in the cell, the text gets highlighted.
1142
     * ```typescript
1143
     * this.cell.highlightText('Cell Value', true);
1144
     * ```
1145
     *
1146
     * @memberof IgxGridCellComponent
1147
     */
1148
    public highlightText(text: string, caseSensitive?: boolean, exactMatch?: boolean): number {
1149
        return this.highlight && this.column.searchable ? this.highlight.highlight(text, caseSensitive, exactMatch) : 0;
160,783✔
1150
    }
1151

1152
    /**
1153
     * Clears the highlight of the text in the cell.
1154
     * ```typescript
1155
     * this.cell.clearHighLight();
1156
     * ```
1157
     *
1158
     * @memberof IgxGridCellComponent
1159
     */
1160
    public clearHighlight() {
1161
        if (this.highlight && this.column.searchable) {
40✔
1162
            this.highlight.clearHighlight();
40✔
1163
        }
1164
    }
1165

1166
    /**
1167
     * @hidden
1168
     * @internal
1169
     */
1170
    public calculateSizeToFit(range: any): number {
1171
        return this.platformUtil.getNodeSizeViaRange(range, this.nativeElement);
214✔
1172
    }
1173

1174
    /**
1175
     * @hidden
1176
     * @internal
1177
     */
1178
    public get searchMetadata() {
1179
        const meta = new Map<string, any>();
303,177✔
1180
        meta.set('pinned', this.grid.isRecordPinnedByViewIndex(this.intRow.index));
303,177✔
1181
        return meta;
303,177✔
1182
    }
1183

1184
    /**
1185
     * @hidden
1186
     * @internal
1187
     */
1188
    public getTransformedFieldName(field: string): string {
NEW
1189
        return field?.replace(/\./g, '_');
×
1190
    }
1191

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

1201
        let editableArgs;
1202
        const crud = this.grid.crudService;
923✔
1203
        const editableCell = this.grid.crudService.cell;
923✔
1204
        const editMode = !!(crud.row || crud.cell);
923✔
1205

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

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

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

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

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

1240
    private addPointerListeners(selection) {
1241
        if (selection !== GridSelectionMode.multiple) {
152,446✔
1242
            return;
604✔
1243
        }
1244
        this.nativeElement.addEventListener('pointerenter', this.pointerenter);
151,842✔
1245
        this.nativeElement.addEventListener('pointerup', this.pointerup);
151,842✔
1246
        this.nativeElement.addEventListener('focusout', this.focusout);
151,842✔
1247
    }
1248

1249
    private removePointerListeners(selection) {
1250
        if (selection !== GridSelectionMode.multiple) {
151,953✔
1251
            return;
852✔
1252
        }
1253
        this.nativeElement.removeEventListener('pointerenter', this.pointerenter);
151,101✔
1254
        this.nativeElement.removeEventListener('pointerup', this.pointerup);
151,101✔
1255
        this.nativeElement.removeEventListener('focusout', this.focusout);
151,101✔
1256
    }
1257

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

© 2025 Coveralls, Inc