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

IgniteUI / igniteui-angular / 15140530896

20 May 2025 02:39PM CUT coverage: 91.597%. Remained the same
15140530896

Pull #15000

github

web-flow
Merge a4f1b34ad into 310d1baa8
Pull Request #15000: fix(grid): add coerceToInt attribute to IPinningConfig and pagingMode props - 18.2.x

13004 of 15241 branches covered (85.32%)

26347 of 28764 relevant lines covered (91.6%)

34026.64 hits per line

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

56.86
/projects/igniteui-angular/src/lib/grids/grouping/tree-grid-group-by-area.component.ts
1
import {
2
    AfterContentInit,
3
    Component,
4
    ElementRef,
5
    Input,
6
    IterableDiffer,
7
    IterableDiffers,
8
    OnDestroy,
9
    booleanAttribute,
10
} from '@angular/core';
11
import { Subject } from 'rxjs';
12
import { takeUntil } from 'rxjs/operators';
13
import { IChipsAreaReorderEventArgs } from '../../chips/public_api';
14
import { PlatformUtil } from '../../core/utils';
15
import { IGroupingExpression } from '../../data-operations/grouping-expression.interface';
16
import { ISortingExpression } from '../../data-operations/sorting-strategy';
17
import { IgxGroupByAreaDirective, IgxGroupByMetaPipe } from './group-by-area.directive';
18
import { IgxDropDirective } from '../../directives/drag-drop/drag-drop.directive';
19
import { IgxGroupAreaDropDirective } from '../grid.directives';
20
import { IgxSuffixDirective } from '../../directives/suffix/suffix.directive';
21
import { IgxIconComponent } from '../../icon/icon.component';
22
import { IgxChipComponent } from '../../chips/chip.component';
23
import { NgFor, NgTemplateOutlet } from '@angular/common';
24
import { IgxChipsAreaComponent } from '../../chips/chips-area.component';
25

26
/**
27
 * An internal component representing the group-by drop area for the igx-grid component.
28
 *
29
 * @hidden @internal
30
 */
31
@Component({
32
    selector: 'igx-tree-grid-group-by-area',
33
    templateUrl: 'group-by-area.component.html',
34
    providers: [{ provide: IgxGroupByAreaDirective, useExisting: IgxTreeGridGroupByAreaComponent }],
35
    standalone: true,
36
    imports: [IgxChipsAreaComponent, NgFor, IgxChipComponent, IgxIconComponent, IgxSuffixDirective, IgxGroupAreaDropDirective, IgxDropDirective, NgTemplateOutlet, IgxGroupByMetaPipe]
37
})
38
export class IgxTreeGridGroupByAreaComponent extends IgxGroupByAreaDirective implements AfterContentInit, OnDestroy {
2✔
39
    @Input({ transform: booleanAttribute })
40
    public get hideGroupedColumns() {
41
        return this._hideGroupedColumns;
4✔
42
    }
43

44
    public set hideGroupedColumns(value: boolean) {
45
        if (this.grid?.columns && this.expressions) {
10✔
46
            this.setColumnsVisibility(value);
10✔
47
        }
48

49
        this._hideGroupedColumns = value;
10✔
50
    }
51

52
    private _hideGroupedColumns = false;
12✔
53
    private groupingDiffer: IterableDiffer<IGroupingExpression>;
54
    private destroy$ = new Subject<any>();
12✔
55

56
    constructor(private differs: IterableDiffers, ref: ElementRef<HTMLElement>, platform: PlatformUtil) {
12✔
57
        super(ref, platform);
12✔
58
    }
59

60
    public ngAfterContentInit(): void {
61
        if (this.grid.columns && this.expressions) {
12✔
62
            this.groupingDiffer = this.differs.find(this.expressions).create();
12✔
63
            this.updateColumnsVisibility();
12✔
64
        }
65

66
        this.grid.sortingExpressionsChange.pipe(takeUntil(this.destroy$)).subscribe((sortingExpressions: ISortingExpression[]) => {
12✔
67
            if (!this.expressions || !this.expressions.length) {
×
68
                return;
×
69
            }
70

71
            let changed = false;
×
72

73
            sortingExpressions.forEach((sortExpr: ISortingExpression) => {
×
74
                const fieldName = sortExpr.fieldName;
×
75
                const groupingExpr = this.expressions.find(ex => ex.fieldName === fieldName);
×
76
                if (groupingExpr && groupingExpr.dir !== sortExpr.dir) {
×
77
                    groupingExpr.dir = sortExpr.dir;
×
78
                    changed = true;
×
79
                }
80
            });
81

82
            if (changed) {
×
83
                this.expressions = [...this.expressions];
×
84
            }
85
        });
86
    }
87

88
    public ngOnDestroy(): void {
89
        this.destroy$.next(true);
12✔
90
        this.destroy$.complete();
12✔
91
    }
92

93
    public handleReorder(event: IChipsAreaReorderEventArgs) {
94
        const { chipsArray, originalEvent } = event;
×
95
        const newExpressions = this.getReorderedExpressions(chipsArray);
×
96

97
        this.chipExpressions = newExpressions;
×
98

99
        // When reordered using keyboard navigation, we don't have `onMoveEnd` event.
100
        if (originalEvent instanceof KeyboardEvent) {
×
101
            this.expressions = newExpressions;
×
102
        }
103
    }
104

105
    public handleMoveEnd() {
106
        this.expressions = this.chipExpressions;
×
107
    }
108

109
    public groupBy(expression: IGroupingExpression) {
110
        this.expressions.push(expression);
×
111
        this.expressions = [...this.expressions];
×
112
    }
113

114
    public clearGrouping(name: string) {
115
        this.expressions = this.expressions.filter(item => item.fieldName !== name);
×
116
        this.grid.sortingExpressions = this.grid.sortingExpressions.filter(item => item.fieldName !== name);
×
117
        this.grid.notifyChanges(true);
×
118
    }
119

120
    protected override expressionsChanged() {
121
        this.updateColumnsVisibility();
11✔
122
    }
123

124
    private updateColumnsVisibility() {
125
        if (this.groupingDiffer && this.grid.columns && !this.grid.hasColumnLayouts) {
23✔
126
            const changes = this.groupingDiffer.diff(this.expressions);
15✔
127
            if (changes && this.grid.columns.length > 0) {
15✔
128
                changes.forEachAddedItem((rec) => {
3✔
129
                    const col = this.grid.getColumnByName(rec.item.fieldName);
1✔
130
                    col.hidden = this.hideGroupedColumns;
1✔
131
                });
132
                changes.forEachRemovedItem((rec) => {
3✔
133
                    const col = this.grid.getColumnByName(rec.item.fieldName);
2✔
134
                    col.hidden = false;
2✔
135
                });
136
            }
137
        }
138
    }
139

140
    private setColumnsVisibility(value) {
141
        if (this.grid.columns.length > 0 && !this.grid.hasColumnLayouts) {
10✔
142
            this.expressions.forEach((expr) => {
1✔
143
                const col = this.grid.getColumnByName(expr.fieldName);
2✔
144
                col.hidden = value;
2✔
145
            });
146
        }
147
    }
148
}
149

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