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

IgniteUI / igniteui-angular / 10936316455

19 Sep 2024 07:21AM UTC coverage: 91.582% (+0.001%) from 91.581%
10936316455

push

github

web-flow
fix(grid): add missing attribute for selectedrows prop (#14717)

12789 of 14994 branches covered (85.29%)

26012 of 28403 relevant lines covered (91.58%)

33736.83 hits per line

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

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

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

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

56
/**
57
 * Providing reference to `IgxGridCellComponent`:
58
 * ```typescript
59
 * @ViewChild('grid', { read: IgxGridComponent })
60
 *  public grid: IgxGridComponent;
61
 * ```
62
 * ```typescript
63
 *  let column = this.grid.columnList.first;
64
 * ```
65
 * ```typescript
66
 *  let cell = column.cells[0];
67
 * ```
68
 */
69
@Component({
70
    changeDetection: ChangeDetectionStrategy.OnPush,
71
    selector: 'igx-grid-cell',
72
    templateUrl: './cell.component.html',
73
    providers: [HammerGesturesManager],
74
    standalone: true,
75
    imports: [
76
        NgIf,
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 {
2✔
105
    private _destroy$ = new Subject<void>();
149,926✔
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,187,027✔
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,697,276✔
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);
1,683✔
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);
632,056✔
260
        const ctx: IgxCellTemplateContext = {
632,056✔
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) {
632,056✔
272
            ctx.formControl = this.formControl;
2,385✔
273
        }
274
        if (this.isInvalid) {
632,056✔
275
            ctx.defaultErrorTemplate = this.defaultErrorTemplate;
414✔
276
        }
277
        return ctx;
632,056✔
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) {
315,983✔
290
            const inlineEditorTemplate = this.column.inlineEditorTemplate;
1,191✔
291
            return inlineEditorTemplate ? inlineEditorTemplate : this.inlineEditorTemplate;
1,191✔
292
        }
293
        if (this.cellTemplate) {
314,792✔
294
            return this.cellTemplate;
657✔
295
        }
296
        if (this.grid.rowEditable && this.intRow.addRowUI) {
314,135✔
297
            return this.addRowCellTemplate;
1,875✔
298
        }
299
        return this.defaultCellTemplate;
312,260✔
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) {
315,935!
312
            return this.pinnedIndicator;
×
313
        }
314
        return this.defaultPinnedIndicator;
315,935✔
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,481,477✔
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,746,174✔
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,123✔
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,748,867✔
367
    }
368

369
    public set visibleColumnIndex(val) {
370
        this._vIndex = val;
156,376✔
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;
442✔
383
        const rowID = primaryKey ? this.rowData[primaryKey] : this.rowData;
442✔
384
        return { rowID, columnID: this.columnIndex, rowIndex: this.rowIndex };
442✔
385
    }
386

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

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

398
        if (this.formatter) {
1,180,044✔
399
            return this.formatter(this.value, this.rowData, this.columnData);
20,991✔
400
        }
401

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

405
        switch (this.column.dataType) {
1,159,053✔
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,830✔
410
            case GridColumnDataType.Date:
411
            case GridColumnDataType.DateTime:
412
            case GridColumnDataType.Time:
413
                return formatDate(this.value, args.format, locale, args.timezone);
164,944✔
414
        }
415
        return this.value;
972,852✔
416
    }
417

418
    @HostBinding('class.igx-grid__td--bool-true')
419
    public get booleanClass() {
420
        return this.column.dataType === 'boolean' && this.value;
1,185,199✔
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,252,001✔
433
    }
434

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

444
    public set cellSelectionMode(value) {
445
        if (this._cellSelection === value) {
150,294✔
446
            return;
149,322✔
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;
155,220✔
465
        this.highlightText(this._lastSearchInfo.searchText, this._lastSearchInfo.caseSensitive, this._lastSearchInfo.exactMatch);
155,220✔
466
    }
467

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

476
    /**
477
     * @hidden
478
     * @internal
479
     */
480
    @Input()
481
    @HostBinding('class.igx-grid__td--pinned-first')
482
    public firstPinned = false;
149,926✔
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;
149,926✔
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';
149,926✔
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,185,200✔
517
    }
518

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

529
    /** @hidden @internal */
530
    public get ariaErrorMessage() {
531
        return this.grid.id + '_' + this.column.field + '_' + this.intRow.index + '_error';
245✔
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
        const isInvalid = this.formGroup?.get(this.column?.field)?.invalid && this.formGroup?.get(this.column?.field)?.touched;
4,506,769✔
542
        return !this.intRow.deleted && isInvalid;
4,506,769✔
543
    }
544

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

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

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

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

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

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

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

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

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

597
    /**
598
     * @hidden
599
     */
600
    @Input()
601
    @HostBinding('class.igx-grid__td--active')
602
    public active = false;
149,926✔
603

604
    @HostBinding('attr.aria-selected')
605
    public get ariaSelected() {
606
        return this.selected || this.column.selected || this.intRow.selected;
1,185,199✔
607
    }
608

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

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

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

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

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

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

690
    /**
691
     * @hidden
692
     */
693
    @Input()
694
    @HostBinding('class.igx-grid__td--row-pinned-first')
695
    public displayPinnedChip = false;
149,926✔
696

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

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

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

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

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

716
    @ViewChild(IgxTextHighlightDirective, { read: IgxTextHighlightDirective })
717
    protected set highlight(value: IgxTextHighlightDirective) {
718
        this._highlight = value;
151,856✔
719

720
        if (this._highlight && this.grid.lastSearchInfo.searchText) {
151,856✔
721
            this._highlight.highlight(this.grid.lastSearchInfo.searchText,
395✔
722
                this.grid.lastSearchInfo.caseSensitive,
723
                this.grid.lastSearchInfo.exactMatch);
724
            this._highlight.activateIfNecessary();
395✔
725
        }
726
    }
727

728
    protected get highlight() {
729
        return this._highlight;
348,123✔
730
    }
731

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

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

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

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

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

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

795
    protected _lastSearchInfo: ISearchInfo;
796
    private _highlight: IgxTextHighlightDirective;
797
    private _cellSelection: GridSelectionMode = GridSelectionMode.multiple;
149,926✔
798
    private _vIndex = -1;
149,926✔
799

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

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

825
        this.grid.doubleClick.emit({
148✔
826
            cell: this.getCellType(),
827
            event
828
        });
829
    };
830

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

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

858
    }
859

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

870
    /**
871
     * @hidden
872
     * @internal
873
     */
874
    public errorShowing = false;
149,926✔
875

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

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

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

934

935

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

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

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

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

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

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

1038
    /**
1039
     * @hidden
1040
     * @internal
1041
     */
1042
    public focusout = () => {
149,926✔
1043
        this.closeErrorTooltip();
38✔
1044
    }
1045

1046
    private closeErrorTooltip() {
1047
        const tooltip = this.errorTooltip.first;
38✔
1048
        if (tooltip) {
38!
1049
            tooltip.close();
×
1050
        }
1051
    }
1052

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

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

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

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

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

1103
        this.grid.navigation.setActiveNode({ row: this.rowIndex, column: this.visibleColumnIndex });
967✔
1104

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

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

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

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

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

1172
    /**
1173
     * @hidden
1174
     * @internal
1175
     */
1176
    private _updateCRUDStatus(event?: Event) {
1177
        if (this.editMode) {
969✔
1178
            return;
47✔
1179
        }
1180

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

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

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

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

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

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

1220
    private addPointerListeners(selection) {
1221
        if (selection !== GridSelectionMode.multiple) {
149,986✔
1222
            return;
604✔
1223
        }
1224
        this.nativeElement.addEventListener('pointerenter', this.pointerenter);
149,382✔
1225
        this.nativeElement.addEventListener('pointerup', this.pointerup);
149,382✔
1226
        this.nativeElement.addEventListener('focusout', this.focusout);
149,382✔
1227
    }
1228

1229
    private removePointerListeners(selection) {
1230
        if (selection !== GridSelectionMode.multiple) {
149,534✔
1231
            return;
852✔
1232
        }
1233
        this.nativeElement.removeEventListener('pointerenter', this.pointerenter);
148,682✔
1234
        this.nativeElement.removeEventListener('pointerup', this.pointerup);
148,682✔
1235
        this.nativeElement.removeEventListener('focusout', this.focusout);
148,682✔
1236
    }
1237

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