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

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

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

0.0
/projects/igniteui-angular/src/lib/grids/grid-public-cell.ts
1
import { CellType, ColumnType, GridType, IGridValidationState, RowType, ValidationStatus } from './common/grid.interface';
2
import { ISelectionNode } from './common/types';
3
import { resolveNestedPath } from '../core/utils';
4

5
export class IgxGridCell implements CellType {
6

7
    /**
8
     * Returns the grid containing the cell.
9
     *
10
     * @memberof IgxGridCell
11
     */
12
    public grid: GridType;
13
    private _row: RowType;
14
    private _rowIndex: number;
15
    private _column: ColumnType;
16
    private _columnField: string;
17

18
    /**
19
     * @hidden
20
     */
21
    constructor(
22
        grid: GridType,
23
        row: number | RowType,
24
        column: ColumnType) {
UNCOV
25
        this.grid = grid;
×
UNCOV
26
        if (typeof row === 'number') {
×
UNCOV
27
            this._rowIndex = row;
×
28
        } else {
UNCOV
29
            this._row = row;
×
UNCOV
30
            this._rowIndex = row.index;
×
31
        }
UNCOV
32
        this._column = column;
×
33
    }
34

35
    /**
36
     * Returns the row containing the cell.
37
     * ```typescript
38
     * let row = this.cell.row;
39
     * ```
40
     *
41
     * @memberof IgxGridCell
42
     */
43
    public get row(): RowType {
UNCOV
44
        return this._row || this.grid.createRow(this._rowIndex);
×
45
    }
46

47
    /**
48
     * Returns the column of the cell.
49
     * ```typescript
50
     * let column = this.cell.column;
51
     * ```
52
     *
53
     * @memberof IgxGridCell
54
     */
55
    public get column(): ColumnType {
UNCOV
56
        return this._column;
×
57
    }
58

59
    /**
60
     * Gets the current edit value while a cell is in edit mode.
61
     * ```typescript
62
     * let editValue = this.cell.editValue;
63
     * ```
64
     *
65
     * @memberof IgxGridCell
66
     */
67
    public get editValue(): any {
UNCOV
68
        if (this.isCellInEditMode()) {
×
UNCOV
69
            return this.grid.crudService.cell.editValue;
×
70
        }
71
    }
72

73
    /**
74
     * Sets the current edit value while a cell is in edit mode.
75
     * Only for cell editing mode.
76
     * ```typescript
77
     * this.cell.editValue = value;
78
     * ```
79
     *
80
     * @memberof IgxGridCell
81
     */
82
    public set editValue(value: any) {
UNCOV
83
        if (this.isCellInEditMode()) {
×
UNCOV
84
            this.grid.crudService.cell.editValue = value;
×
85
        }
86
    }
87

88
    /**
89
     * Gets the validation status and errors, if any.
90
     * ```typescript
91
     * let validation = this.cell.validation;
92
     * let errors = validation.errors;
93
     * ```
94
     */
95

96
    public get validation(): IGridValidationState {
UNCOV
97
        const form = this.grid.validation.getFormControl(this.row.key, this.column.field);
×
UNCOV
98
        return { status: form?.status as ValidationStatus || 'VALID', errors: form?.errors } as const;
×
99
    }
100

101
    /**
102
     * Returns whether the cell is editable..
103
     *
104
     * @memberof IgxGridCell
105
     */
106
    public get editable(): boolean {
UNCOV
107
        return this.column.editable && !this.row?.disabled;
×
108
    }
109

110
    /**
111
     * Gets the width of the cell.
112
     * ```typescript
113
     * let cellWidth = this.cell.width;
114
     * ```
115
     *
116
     * @memberof IgxGridCell
117
     */
118
    public get width(): string {
UNCOV
119
        return this.column.width;
×
120
    }
121

122
    /**
123
     * Returns the cell value.
124
     *
125
     * @memberof IgxGridCell
126
     */
127
    public get value(): any {
128
        // will return undefined for a column layout, because getCellByColumnVisibleIndex may return the column layout at that index.
129
        // getCellByColumnVisibleIndex is deprecated and will be removed in future version
UNCOV
130
        return this.column.field ?
×
131
            this.column.hasNestedPath ? resolveNestedPath(this.row?.data, this.column.field) : this.row?.data[this.column.field]
×
132
            : undefined;
133
    }
134

135
    /**
136
     * Updates the cell value.
137
     *
138
     * @memberof IgxGridCell
139
     */
140
    public set value(val: any) {
UNCOV
141
        this.update(val);
×
142
    }
143

144
    /**
145
     * Gets the cell id.
146
     * A cell in the grid is identified by:
147
     * - rowID - primaryKey data value or the whole rowData, if the primaryKey is omitted.
148
     * - rowIndex - the row index
149
     * - columnID - column index
150
     *
151
     * ```typescript
152
     * let cellID = cell.id;
153
     * ```
154
     *
155
     * @memberof IgxGridCell
156
     */
157
    public get id(): any {
UNCOV
158
        const primaryKey = this.grid.primaryKey;
×
UNCOV
159
        const rowID = primaryKey ? this.row?.data[primaryKey] : this.row?.data;
×
UNCOV
160
        return { rowID, columnID: this.column.index, rowIndex: this._rowIndex || this.row?.index };
×
161
    }
162

163
    /**
164
     * Returns if the row is currently in edit mode.
165
     *
166
     * @memberof IgxGridCell
167
     */
168
    public get editMode(): boolean {
UNCOV
169
        return this.isCellInEditMode();
×
170
    }
171

172
    /**
173
     * Starts/ends edit mode for the cell.
174
     *
175
     * ```typescript
176
     * cell.editMode  = !cell.editMode;
177
     * ```
178
     *
179
     * @memberof IgxGridCell
180
     */
181
    public set editMode(value: boolean) {
UNCOV
182
        const isInEditMode = this.isCellInEditMode();
×
UNCOV
183
        if (!this.row || this.row?.deleted || isInEditMode === value) {
×
UNCOV
184
            return;
×
185
        }
UNCOV
186
        if (this.editable && value) {
×
UNCOV
187
            this.endEdit();
×
188
            // TODO possibly define similar method in gridAPI, which does not emit event
UNCOV
189
            this.grid.crudService.enterEditMode(this);
×
190
        } else {
UNCOV
191
            this.grid.crudService.endCellEdit();
×
192
        }
UNCOV
193
        this.grid.notifyChanges();
×
194
    }
195

196
    /**
197
     * Gets whether the cell is selected.
198
     * ```typescript
199
     * let isSelected = this.cell.selected;
200
     * ```
201
     *
202
     *
203
     * @memberof IgxGridCell
204
     */
205
    public get selected(): boolean {
UNCOV
206
        return this.grid.selectionService.selected(this.selectionNode);
×
207
    }
208

209
    /**
210
     * Selects/deselects the cell.
211
     * ```typescript
212
     * this.cell.selected = true.
213
     * ```
214
     *
215
     *
216
     * @memberof IgxGridCell
217
     */
218
    public set selected(val: boolean) {
UNCOV
219
        const node = this.selectionNode;
×
UNCOV
220
        if (val) {
×
UNCOV
221
            this.grid.selectionService.add(node);
×
222
        } else {
UNCOV
223
            this.grid.selectionService.remove(node);
×
224
        }
UNCOV
225
        this.grid.notifyChanges();
×
226
    }
227

228
    public get active() {
UNCOV
229
        const node = this.grid.navigation.activeNode;
×
UNCOV
230
        return node ? node.row === this.row?.index && node.column === this.column.visibleIndex : false;
×
231
    }
232

233

234
    /**
235
     * Updates the cell value.
236
     *
237
     * ```typescript
238
     * cell.update(newValue);
239
     * ```
240
     *
241
     * @memberof IgxGridCell
242
     */
243
    public update(val: any): void {
UNCOV
244
        if (this.row?.deleted) {
×
245
            return;
×
246
        }
247

UNCOV
248
        this.endEdit();
×
249

UNCOV
250
        const cell = this.isCellInEditMode() ? this.grid.crudService.cell : this.grid.crudService.createCell(this);
×
UNCOV
251
        cell.editValue = val;
×
UNCOV
252
        this.grid.gridAPI.update_cell(cell);
×
UNCOV
253
        this.grid.crudService.endCellEdit();
×
UNCOV
254
        this.grid.notifyChanges();
×
255
    }
256

257
    protected get selectionNode(): ISelectionNode {
UNCOV
258
        return {
×
259
            row: this.row?.index,
260
            column: this.column.columnLayoutChild ? this.column.parent.visibleIndex : this.column.visibleIndex,
×
261
            layout: this.column.columnLayoutChild ? {
×
262
                rowStart: this.column.rowStart,
263
                colStart: this.column.colStart,
264
                rowEnd: this.column.rowEnd,
265
                colEnd: this.column.colEnd,
266
                columnVisibleIndex: this.column.visibleIndex
267
            } : null
268
        };
269
    }
270

271
    private isCellInEditMode(): boolean {
UNCOV
272
        if (this.grid.crudService.cellInEditMode) {
×
UNCOV
273
            const cellInEditMode = this.grid.crudService.cell.id;
×
UNCOV
274
            const isCurrentCell = cellInEditMode.rowID === this.id.rowID &&
×
275
                cellInEditMode.rowIndex === this.id.rowIndex &&
276
                cellInEditMode.columnID === this.id.columnID;
UNCOV
277
            return isCurrentCell;
×
278
        }
UNCOV
279
        return false;
×
280
    }
281

282
    private endEdit(): void {
UNCOV
283
        if (!this.isCellInEditMode()) {
×
UNCOV
284
            this.grid.gridAPI.update_cell(this.grid.crudService.cell);
×
UNCOV
285
            this.grid.crudService.endCellEdit();
×
286
        }
287
    }
288
}
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