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

IgniteUI / igniteui-angular / 6146764501

11 Sep 2023 01:01PM CUT coverage: 92.263%. Remained the same
6146764501

push

github

web-flow
Merge pull request #13437 from IgniteUI/thristodorova/fix-13433-16.0.x

fix(grid): add return type and return value to endEdit method

15311 of 17991 branches covered (0.0%)

1 of 1 new or added line in 1 file covered. (100.0%)

26844 of 29095 relevant lines covered (92.26%)

29497.61 hits per line

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

98.18
/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
    /**
46,620✔
8
     * Returns the grid containing the cell.
46,620✔
9
     *
45,537✔
10
     * @memberof IgxGridCell
11
     */
12
    public grid: GridType;
1,083✔
13
    private _row: RowType;
1,083✔
14
    private _rowIndex: number;
15
    private _column: ColumnType;
46,620✔
16
    private _columnField: string;
17

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

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

47
    /**
48
     * Returns the column of the cell.
50✔
49
     * ```typescript
49✔
50
     * let column = this.cell.column;
51
     * ```
52
     *
53
     * @memberof IgxGridCell
54
     */
55
    public get column(): ColumnType {
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;
28✔
63
     * ```
27✔
64
     *
65
     * @memberof IgxGridCell
66
     */
67
    public get editValue(): any {
68
        if (this.isCellInEditMode()) {
69
            return this.grid.crudService.cell.editValue;
70
        }
71
    }
72

73
    /**
74
     * Sets the current edit value while a cell is in edit mode.
90✔
75
     * Only for cell editing mode.
90!
76
     * ```typescript
77
     * this.cell.editValue = value;
78
     * ```
79
     *
80
     * @memberof IgxGridCell
81
     */
82
    public set editValue(value: any) {
83
        if (this.isCellInEditMode()) {
78✔
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
     */
1,021✔
95

96
    public get validation(): IGridValidationState {
97
        const form = this.grid.validation.getFormControl(this.row.key, this.column.field);
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
1,297!
105
     */
1,297✔
106
    public get editable(): boolean {
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
     * ```
8✔
115
     *
116
     * @memberof IgxGridCell
117
     */
118
    public get width(): string {
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
130
        return this.column.field ?
766✔
131
            this.column.hasNestedPath ? resolveNestedPath(this.row?.data, this.column.field) : this.row?.data[this.column.field]
766✔
132
            : undefined;
766✔
133
    }
134

135
    /**
136
     * Updates the cell value.
137
     *
138
     * @memberof IgxGridCell
139
     */
140
    public set value(val: any) {
157✔
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;
86✔
153
     * ```
86✔
154
     *
8✔
155
     * @memberof IgxGridCell
156
     */
78✔
157
    public get id(): any {
73✔
158
        const primaryKey = this.grid.primaryKey;
159
        const rowID = primaryKey ? this.row?.data[primaryKey] : this.row?.data;
73✔
160
        return { rowID, columnID: this.column.index, rowIndex: this._rowIndex || this.row?.index };
161
    }
162

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

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

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

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

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

233

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

119✔
248
        this.endEdit();
249

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

257
    protected get selectionNode(): ISelectionNode {
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 {
272
        if (this.grid.crudService.cellInEditMode) {
273
            const cellInEditMode = this.grid.crudService.cell.id;
274
            const isCurrentCell = cellInEditMode.rowID === this.id.rowID &&
275
                cellInEditMode.rowIndex === this.id.rowIndex &&
276
                cellInEditMode.columnID === this.id.columnID;
277
            return isCurrentCell;
278
        }
279
        return false;
280
    }
281

282
    private endEdit(): void {
283
        if (!this.isCellInEditMode()) {
284
            this.grid.gridAPI.update_cell(this.grid.crudService.cell);
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