• 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

31.71
/projects/igniteui-angular/src/lib/grids/columns/column-group.component.ts
1
import {
2
    AfterContentInit,
3
    Component,
4
    ContentChildren,
5
    ChangeDetectionStrategy,
6
    Input,
7
    forwardRef,
8
    QueryList,
9
    TemplateRef,
10
    booleanAttribute
11
} from '@angular/core';
12
import { takeUntil } from 'rxjs/operators';
13

14
import { IgxColumnComponent } from './column.component';
15
import { flatten } from '../../core/utils';
16
import { CellType, ColumnType, IgxColumnTemplateContext } from '../common/grid.interface';
17

18
/* blazorElement */
19
/* omitModule */
20
/* wcElementTag: igc-column-group */
21
/* additionalIdentifier: Children.Field */
22
/* jsonAPIManageCollectionInMarkup */
23
/* blazorIndirectRender */
24
/**
25
 * **Ignite UI for Angular Column Group**
26
 *
27
 * @igxParent IgxGridComponent, IgxTreeGridComponent, IgxHierarchicalGridComponent, IgxColumnGroupComponent, IgxRowIslandComponent
28
 */
29
@Component({
30
    changeDetection: ChangeDetectionStrategy.OnPush,
31
    providers: [{ provide: IgxColumnComponent, useExisting: forwardRef(() => IgxColumnGroupComponent) }],
1✔
32
    selector: 'igx-column-group',
33
    template: `@if (platform.isElements) {
34
        <div #sink style="display: none;">
35
            <ng-content select="igx-column,igc-column,igx-column-group,igc-column-group"></ng-content>
36
        </div>
37
    }`,
38
    standalone: true
39
})
40
export class IgxColumnGroupComponent extends IgxColumnComponent implements AfterContentInit {
2✔
41

42
    /* blazorInclude */
43
    /* contentChildren */
44
    /* blazorTreatAsCollection */
45
    /* blazorCollectionName: ColumnCollection */
46
    /* blazorCollectionItemName: Column */
47
    /* alternateType: HTMLCollection */
48
    /**
49
     * @deprecated in version 18.1.0. Use the `childColumns` property instead.
50
     */
51
    @ContentChildren(IgxColumnComponent, { read: IgxColumnComponent,  })
52
    public override children = new QueryList<IgxColumnComponent>();
1✔
53

54
    /**
55
     * Set if the column group is collapsible.
56
     * Default value is `false`
57
     * ```html
58
     *  <igx-column-group [collapsible] = "true"></igx-column-group>
59
     * ```
60
     *
61
     * @memberof IgxColumnGroupComponent
62
     */
63
    @Input({ transform: booleanAttribute })
64
    public override set collapsible(value: boolean) {
UNCOV
65
        this._collapsible = value;
×
UNCOV
66
        this.collapsibleChange.emit(this._collapsible);
×
UNCOV
67
        if (this.children && !this.hidden) {
×
UNCOV
68
            if (this._collapsible) {
×
UNCOV
69
                this.setExpandCollapseState();
×
70
            } else {
UNCOV
71
                this.children.forEach(child => child.hidden = false);
×
72
            }
73
        }
74
    }
75
    public override get collapsible() {
76
        return this._collapsible && this.checkCollapsibleState();
19!
77
    }
78

79
    /**
80
     * Set whether the group is expanded or collapsed initially.
81
     * Applied only if the collapsible property is set to `true`
82
     * Default value is `true`
83
     * ```html
84
     *  const state = false
85
     *  <igx-column-group [(expand)] = "state"></igx-column-group>
86
     * ```
87
     *
88
     * @memberof IgxColumnGroupComponent
89
     */
90
    @Input({ transform: booleanAttribute })
91
    public override set expanded(value: boolean) {
UNCOV
92
        this._expanded = value;
×
UNCOV
93
        this.expandedChange.emit(this._expanded);
×
UNCOV
94
        if (!this.collapsible) {
×
UNCOV
95
            return;
×
96
        }
UNCOV
97
        if (!this.hidden && this.children) {
×
UNCOV
98
            this.setExpandCollapseState();
×
99
        }
100
    }
101
    public override get expanded() {
102
        return this._expanded;
9✔
103
    }
104

105
    /**
106
     * Gets the column group `summaries`.
107
     * ```typescript
108
     * let columnGroupSummaries = this.columnGroup.summaries;
109
     * ```
110
     *
111
     * @memberof IgxColumnGroupComponent
112
     */
113
    @Input()
114
    public override get summaries(): any {
UNCOV
115
        return this._summaries;
×
116
    }
117

118
     /* blazorSuppress */
119
    /**
120
     * Sets the column group `summaries`.
121
     * ```typescript
122
     * this.columnGroup.summaries = IgxNumberSummaryOperand;
123
     * ```
124
     *
125
     * @memberof IgxColumnGroupComponent
126
     */
127
    public override set summaries(classRef: any) { }
128

129
     /* blazorSuppress */
130
    /**
131
     * Sets/gets whether the column group is `searchable`.
132
     * Default value is `true`.
133
     * ```typescript
134
     * let isSearchable =  this.columnGroup.searchable;
135
     * ```
136
     * ```html
137
     *  <igx-column-group [searchable] = "false"></igx-column-group>
138
     * ```
139
     *
140
     * @memberof IgxColumnGroupComponent
141
     */
142
    @Input({ transform: booleanAttribute })
143
    public override searchable = true;
1✔
144
    /**
145
     * Gets the column group `filters`.
146
     * ```typescript
147
     * let columnGroupFilters = this.columnGroup.filters;
148
     * ```
149
     *
150
     * @memberof IgxColumnGroupComponent
151
     */
152
    @Input()
153
    public override get filters(): any {
UNCOV
154
        return this._filters;
×
155
    }
156

157
     /* blazorSuppress */
158
    /**
159
     * Sets the column group `filters`.
160
     * ```typescript
161
     * this.columnGroup.filters = IgxStringFilteringOperand;
162
     * ```
163
     *
164
     * @memberof IgxColumnGroupComponent
165
     */
166
    public override set filters(classRef: any) { }
167

168
    /**
169
     * Returns if the column group is selectable
170
     * ```typescript
171
     * let columnGroupSelectable = this.columnGroup.selectable;
172
     * ```
173
     *
174
     * @memberof IgxColumnGroupComponent
175
     */
176
    public override get selectable(): boolean {
UNCOV
177
        return this.children && this.children.some(child => child.selectable);
×
178
    }
179

180
    /**
181
     * @hidden
182
     */
183
    public override set selectable(value: boolean) { }
184

185
    /**
186
     * @hidden
187
     */
188
    public override get bodyTemplate(): TemplateRef<any> {
UNCOV
189
        return this._bodyTemplate;
×
190
    }
191
    /**
192
     * @hidden
193
     */
194
    public override set bodyTemplate(template: TemplateRef<any>) { }
195

196
    /**
197
     * Allows you to define a custom template for expand/collapse indicator
198
     *
199
     * @memberof IgxColumnGroupComponent
200
     */
201
    @Input()
202
    public override collapsibleIndicatorTemplate: TemplateRef<IgxColumnTemplateContext>;
203

204
    /**
205
     * @hidden
206
     */
207
    public override get inlineEditorTemplate(): TemplateRef<any> {
UNCOV
208
        return this._inlineEditorTemplate;
×
209
    }
210
    /**
211
     * @hidden
212
     */
213
    public override set inlineEditorTemplate(template: TemplateRef<any>) { }
214
    /**
215
     * @hidden @internal
216
     */
217
    public override get cells(): CellType[] {
218
        return [];
×
219
    }
220
    /**
221
     * Gets whether the column group is hidden.
222
     * ```typescript
223
     * let isHidden = this.columnGroup.hidden;
224
     * ```
225
     *
226
     * @memberof IgxColumnGroupComponent
227
     */
228
    @Input({ transform: booleanAttribute })
229
    public override get hidden() {
230
        return this.allChildren.every(c => c.hidden);
14✔
231
    }
232

233
    /* blazorSuppress */
234
    /**
235
     * Sets the column group hidden property.
236
     * ```html
237
     * <igx-column [hidden] = "true"></igx-column>
238
     * ```
239
     *
240
     * Two-way data binding
241
     * ```html
242
     * <igx-column [(hidden)] = "model.columns[0].isHidden"></igx-column>
243
     * ```
244
     *
245
     * @memberof IgxColumnGroupComponent
246
     */
247
    public override set hidden(value: boolean) {
UNCOV
248
        this._hidden = value;
×
UNCOV
249
        this.hiddenChange.emit(this._hidden);
×
UNCOV
250
        if (this._hidden || !this.collapsible) {
×
UNCOV
251
            this.children.forEach(child => child.hidden = this._hidden);
×
252
        } else {
UNCOV
253
            this.children.forEach(c => {
×
UNCOV
254
                if (c.visibleWhenCollapsed === undefined) {
×
255
                    c.hidden = false; return;
×
256
                }
UNCOV
257
                c.hidden = this.expanded ? c.visibleWhenCollapsed : !c.visibleWhenCollapsed;
×
258
            });
259
        }
260
    }
261

262
    /**
263
     * Returns if the column group is selected.
264
     * ```typescript
265
     * let isSelected = this.columnGroup.selected;
266
     * ```
267
     *
268
     * @memberof IgxColumnGroupComponent
269
     */
270
    public override get selected(): boolean {
271
        const selectableChildren = this.allChildren.filter(c => !c.columnGroup && c.selectable && !c.hidden);
36✔
272
        return selectableChildren.length > 0 && selectableChildren.every(c => c.selected);
18✔
273
    }
274

275
     /* blazorSuppress */
276
    /**
277
     * Select/deselect the column group.
278
     * ```typescript
279
     * this.columnGroup.selected = true;
280
     * ```
281
     *
282
     * @memberof IgxColumnGroupComponent
283
     */
284
    public override set selected(value: boolean) {
UNCOV
285
        if (this.selectable) {
×
UNCOV
286
            this.children.forEach(c => {
×
UNCOV
287
                c.selected = value;
×
288
            });
289
        }
290
    }
291

292
    /**
293
     * @hidden
294
     */
295
    public override ngAfterContentInit() {
296
        /*
297
            @ContentChildren with descendants still returns the `parent`
298
            component in the query list.
299
        */
300
        if (this.headTemplate && this.headTemplate.length) {
1!
UNCOV
301
            this._headerTemplate = this.headTemplate.toArray()[0].template;
×
302
        }
303
        if (this.collapseIndicatorTemplate) {
1!
UNCOV
304
            this.collapsibleIndicatorTemplate = this.collapseIndicatorTemplate.template;
×
305
        }
306
        // currently only ivy fixes the issue, we have to slice only if the first child is group
307
        if (this.children.first === this) {
1!
308
            this.children.reset(this.children.toArray().slice(1));
×
309
        }
310
        this.children.forEach(child => {
1✔
311
            child.parent = this;
2✔
312
            if (this.pinned) {
2!
UNCOV
313
                child.pinned = this.pinned;
×
314
            }
315
            if (this._hidden) {
2!
UNCOV
316
                child.hidden = this._hidden;
×
317
            }
318
        });
319
        if (this.collapsible) {
1!
UNCOV
320
            this.setExpandCollapseState();
×
321
        }
322

323
        this.children.changes
1✔
324
            .pipe(takeUntil(this.destroy$))
325
            .subscribe((change: QueryList<IgxColumnComponent>) => {
UNCOV
326
                let shouldReinitPinning = false;
×
UNCOV
327
                change.forEach(x => {
×
UNCOV
328
                    x.parent = this;
×
UNCOV
329
                    if (this.pinned && x.pinned !== this.pinned) {
×
330
                        shouldReinitPinning = true;
×
331
                        x.pinned = this.pinned;
×
332
                    }
333
                });
UNCOV
334
                if (this.collapsible) {
×
UNCOV
335
                    this.setExpandCollapseState();
×
336
                }
UNCOV
337
                if (shouldReinitPinning) {
×
338
                    (this.grid as any).initPinning();
×
339
                }
340
            });
341

342
    }
343

344
    /**
345
     * A list containing all the child columns under this column (if any).
346
     * Empty without children or if this column is not Group or Layout.
347
     */
348
    public override get childColumns(): ColumnType[] {
UNCOV
349
        return this.children.toArray();
×
350
    }
351

352
    /** @hidden @internal **/
353
    public override get allChildren(): IgxColumnComponent[] {
354
        return flatten(this.children.toArray());
64✔
355
    }
356
    /**
357
     * Returns a boolean indicating if the column is a `ColumnGroup`.
358
     * ```typescript
359
     * let isColumnGroup =  this.columnGroup.columnGroup
360
     * ```
361
     *
362
     * @memberof IgxColumnGroupComponent
363
     */
364
    public override get columnGroup() {
365
        return true;
124✔
366
    }
367
    /**
368
     * Returns a boolean indicating if the column is a `ColumnLayout` for multi-row layout.
369
     * ```typescript
370
     * let columnGroup =  this.column.columnGroup;
371
     * ```
372
     *
373
     * @memberof IgxColumnComponent
374
     */
375
    public override get columnLayout() {
376
        return false;
1,868✔
377
    }
378
    /**
379
     * Gets the width of the column group.
380
     * ```typescript
381
     * let columnGroupWidth = this.columnGroup.width;
382
     * ```
383
     *
384
     * @memberof IgxColumnGroupComponent
385
     */
386
    public override get width() {
387
        const width = `${this.children.reduce((acc, val) => {
44✔
388
            if (val.hidden) {
88!
UNCOV
389
                return acc;
×
390
            }
391
            return acc + parseFloat(val.calcWidth);
88✔
392
        }, 0)}`;
393
        return width + 'px';
44✔
394
    }
395

396
     /* blazorSuppress */
397
    public override set width(val) { }
398

399
    /** @hidden @internal **/
400
    public override get resolvedWidth() {
401
        return this.width;
18✔
402
    }
403

404
    /**
405
     * @hidden
406
     */
407
    public override get applySelectableClass(): boolean {
UNCOV
408
        return this._applySelectableClass;
×
409
    }
410

411
    /**
412
     * @hidden
413
     */
414
    public override set applySelectableClass(value: boolean) {
UNCOV
415
        if (this.selectable) {
×
UNCOV
416
            this._applySelectableClass = value;
×
UNCOV
417
            this.children.forEach(c => {
×
UNCOV
418
                c.applySelectableClass = value;
×
419
            });
420
        }
421
    }
422

423
    /**
424
     * @hidden
425
     * Calculates the number of visible columns, based on indexes of first and last visible columns.
426
     */
427
    public override calcChildren(): number {
UNCOV
428
        const visibleChildren = this.allChildren.filter(c => c.visibleIndex > -1);
×
UNCOV
429
        const fi = visibleChildren[0].visibleIndex;
×
UNCOV
430
        const li = visibleChildren[visibleChildren.length - 1].visibleIndex;
×
UNCOV
431
        return li - fi + 1;
×
432
    }
433
}
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