• 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

6.49
/projects/igniteui-angular/src/lib/grids/column-actions/column-actions.component.ts
1
import { Component, DoCheck, EventEmitter, HostBinding, Inject, Input, IterableDiffer, IterableDiffers, Output, Pipe, PipeTransform, QueryList, ViewChildren, booleanAttribute, forwardRef } from '@angular/core';
2
import { ColumnDisplayOrder } from '../common/enums';
3
import { ColumnType, GridType } from '../common/grid.interface';
4
import { IColumnToggledEventArgs } from '../common/events';
5
import { IgxCheckboxComponent } from '../../checkbox/checkbox.component';
6
import { IgxColumnActionsBaseDirective } from './column-actions-base.directive';
7
import { IgxRippleDirective } from '../../directives/ripple/ripple.directive';
8
import { IgxButtonDirective } from '../../directives/button/button.directive';
9
import { IgxInputDirective } from '../../directives/input/input.directive';
10
import { FormsModule } from '@angular/forms';
11
import { IgxInputGroupComponent } from '../../input-group/input-group.component';
12
import { NgIf, NgFor } from '@angular/common';
13

14
let NEXT_ID = 0;
2✔
15
/**
16
 * Providing reference to `IgxColumnActionsComponent`:
17
 * ```typescript
18
 *  @ViewChild('columnActions', { read: IgxColumnActionsComponent })
19
 *  public columnActions: IgxColumnActionsComponent;
20
 */
21
@Component({
22
    selector: 'igx-column-actions',
23
    templateUrl: './column-actions.component.html',
UNCOV
24
    imports: [NgIf, IgxInputGroupComponent, FormsModule, IgxInputDirective, NgFor, IgxCheckboxComponent, IgxButtonDirective, IgxRippleDirective, forwardRef(() => IgxColumnActionEnabledPipe), forwardRef(() => IgxFilterActionColumnsPipe), forwardRef(() => IgxSortActionColumnsPipe)]
×
25
})
26
export class IgxColumnActionsComponent implements DoCheck {
2✔
27

28
    /**
29
     * Gets/Sets the grid to provide column actions for.
30
     *
31
     * @example
32
     * ```typescript
33
     * let grid = this.columnActions.grid;
34
     * ```
35
     */
36
    @Input()
37
    public grid: GridType;
38
    /**
39
     * Gets/sets the indentation of columns in the column list based on their hierarchy level.
40
     *
41
     * @example
42
     * ```
43
     * <igx-column-actions [indentation]="15"></igx-column-actions>
44
     * ```
45
     */
46
    @Input()
UNCOV
47
    public indentation = 30;
×
48
    /**
49
     * Sets/Gets the css class selector.
50
     * By default the value of the `class` attribute is `"igx-column-actions"`.
51
     * ```typescript
52
     * let cssCLass =  this.columnHidingUI.cssClass;
53
     * ```
54
     * ```typescript
55
     * this.columnHidingUI.cssClass = 'column-chooser';
56
     * ```
57
     */
58
    @HostBinding('class')
UNCOV
59
    public cssClass = 'igx-column-actions';
×
60
    /**
61
     * Gets/sets the max height of the columns area.
62
     *
63
     * @remarks
64
     * The default max height is 100%.
65
     * @example
66
     * ```html
67
     * <igx-column-actions [columnsAreaMaxHeight]="200px"></igx-column-actions>
68
     * ```
69
     */
70
    @Input()
UNCOV
71
    public columnsAreaMaxHeight = '100%';
×
72
    /**
73
     * Shows/hides the columns filtering input from the UI.
74
     *
75
     * @example
76
     * ```html
77
     *  <igx-column-actions [hideFilter]="true"></igx-column-actions>
78
     * ```
79
     */
80
    @Input({ transform: booleanAttribute })
UNCOV
81
    public hideFilter = false;
×
82
    /**
83
     * Gets the checkbox components representing column items currently present in the dropdown
84
     *
85
     * @example
86
     * ```typescript
87
     * let columnItems =  this.columnActions.columnItems;
88
     * ```
89
     */
90
    @ViewChildren(IgxCheckboxComponent)
91
    public columnItems: QueryList<IgxCheckboxComponent>;
92
    /**
93
     * Gets/sets the title of the column actions component.
94
     *
95
     * @example
96
     * ```html
97
     * <igx-column-actions [title]="'Pin Columns'"></igx-column-actions>
98
     * ```
99
     */
100
    @Input()
UNCOV
101
    public title = '';
×
102

103
    /**
104
     * An event that is emitted after a column's checked state is changed.
105
     * Provides references to the `column` and the `checked` properties as event arguments.
106
     * ```html
107
     *  <igx-column-actions (columnToggled)="columnToggled($event)"></igx-column-actions>
108
     * ```
109
     */
110
    @Output()
UNCOV
111
    public columnToggled = new EventEmitter<IColumnToggledEventArgs>();
×
112

113
    /**
114
     * @hidden @internal
115
     */
UNCOV
116
    public actionableColumns: ColumnType[] = [];
×
117

118
    /**
119
     * @hidden @internal
120
     */
UNCOV
121
    public filteredColumns: ColumnType[] = [];
×
122

123
    /**
124
     * @hidden @internal
125
     */
UNCOV
126
    public pipeTrigger = 0;
×
127

128
    /**
129
     * @hidden @internal
130
     */
131
    public actionsDirective: IgxColumnActionsBaseDirective;
132

UNCOV
133
    protected _differ: IterableDiffer<any> | null = null;
×
134

135
    /**
136
     * @hidden @internal
137
     */
UNCOV
138
    private _filterColumnsPrompt = '';
×
139

140
    /**
141
     * @hidden @internal
142
     */
UNCOV
143
    private _filterCriteria = '';
×
144

145
    /**
146
     * @hidden @internal
147
     */
UNCOV
148
    private _columnDisplayOrder: ColumnDisplayOrder = ColumnDisplayOrder.DisplayOrder;
×
149

150
    /**
151
     * @hidden @internal
152
     */
153
    private _uncheckAllText: string;
154

155
    /**
156
     * @hidden @internal
157
     */
158
    private _checkAllText: string;
159

160
    /**
161
     * @hidden @internal
162
     */
UNCOV
163
    private _id = `igx-column-actions-${NEXT_ID++}`;
×
164

UNCOV
165
    constructor(private differs: IterableDiffers) {
×
UNCOV
166
        this._differ = this.differs.find([]).create(this.trackChanges);
×
167
    }
168

169
    /**
170
     * Gets the prompt that is displayed in the filter input.
171
     *
172
     * @example
173
     * ```typescript
174
     * let filterColumnsPrompt = this.columnActions.filterColumnsPrompt;
175
     * ```
176
     */
177
    @Input()
178
    public get filterColumnsPrompt(): string {
UNCOV
179
        return this._filterColumnsPrompt;
×
180
    }
181
    /**
182
     * Sets the prompt that is displayed in the filter input.
183
     *
184
     * @example
185
     * ```html
186
     * <igx-column-actions [filterColumnsPrompt]="'Type here to search'"></igx-column-actions>
187
     * ```
188
     */
189
    public set filterColumnsPrompt(value: string) {
UNCOV
190
        this._filterColumnsPrompt = value || '';
×
191
    }
192
    /**
193
     * Gets the value which filters the columns list.
194
     *
195
     * @example
196
     * ```typescript
197
     * let filterCriteria =  this.columnActions.filterCriteria;
198
     * ```
199
     */
200
    @Input()
201
    public get filterCriteria() {
UNCOV
202
        return this._filterCriteria;
×
203
    }
204
    /**
205
     * Sets the value which filters the columns list.
206
     *
207
     * @example
208
     * ```html
209
     *  <igx-column-actions [filterCriteria]="'ID'"></igx-column-actions>
210
     * ```
211
     */
212
    public set filterCriteria(value: string) {
UNCOV
213
        value = value || '';
×
UNCOV
214
        if (value !== this._filterCriteria) {
×
UNCOV
215
            this._filterCriteria = value;
×
UNCOV
216
            this.pipeTrigger++;
×
217
        }
218
    }
219
    /**
220
     * Gets the display order of the columns.
221
     *
222
     * @example
223
     * ```typescript
224
     * let columnDisplayOrder = this.columnActions.columnDisplayOrder;
225
     * ```
226
     */
227
    @Input()
228
    public get columnDisplayOrder() {
UNCOV
229
        return this._columnDisplayOrder;
×
230
    }
231
    /**
232
     * Sets the display order of the columns.
233
     *
234
     * @example
235
     * ```typescript
236
     * this.columnActions.columnDisplayOrder = ColumnDisplayOrder.Alphabetical;
237
     * ```
238
     */
239
    public set columnDisplayOrder(value: ColumnDisplayOrder) {
UNCOV
240
        if (value && value !== this._columnDisplayOrder) {
×
UNCOV
241
            this._columnDisplayOrder = value;
×
UNCOV
242
            this.pipeTrigger++;
×
243
        }
244
    }
245
    /**
246
     * Gets the text of the button that unchecks all columns.
247
     *
248
     * @remarks
249
     * If unset it is obtained from the IgxColumnActionsBased derived directive applied.
250
     * @example
251
     * ```typescript
252
     * let uncheckAllText = this.columnActions.uncheckAllText;
253
     * ```
254
     */
255
    @Input()
256
    public get uncheckAllText() {
UNCOV
257
        return this._uncheckAllText || this.actionsDirective.uncheckAllLabel;
×
258
    }
259
    /**
260
     * Sets the text of the button that unchecks all columns.
261
     *
262
     * @example
263
     * ```html
264
     * <igx-column-actions [uncheckAllText]="'Show All'"></igx-column-actions>
265
     * ```
266
     */
267
    public set uncheckAllText(value: string) {
UNCOV
268
        this._uncheckAllText = value;
×
269
    }
270
    /**
271
     * Gets the text of the button that checks all columns.
272
     *
273
     * @remarks
274
     * If unset it is obtained from the IgxColumnActionsBased derived directive applied.
275
     * @example
276
     * ```typescript
277
     * let uncheckAllText = this.columnActions.uncheckAllText;
278
     * ```
279
     */
280
    @Input()
281
    public get checkAllText() {
UNCOV
282
        return this._checkAllText || this.actionsDirective.checkAllLabel;
×
283
    }
284
    /**
285
     * Sets the text of the button that checks all columns.
286
     *
287
     * @remarks
288
     * If unset it is obtained from the IgxColumnActionsBased derived directive applied.
289
     * @example
290
     * ```html
291
     * <igx-column-actions [checkAllText]="'Hide All'"></igx-column-actions>
292
     * ```
293
     */
294
    public set checkAllText(value: string) {
UNCOV
295
        this._checkAllText = value;
×
296
    }
297

298
    /**
299
     * @hidden @internal
300
     */
301
    public get checkAllDisabled(): boolean {
UNCOV
302
        return this.actionsDirective.allUnchecked;
×
303

304
    }
305
    /**
306
     * @hidden @internal
307
     */
308
    public get uncheckAllDisabled(): boolean {
UNCOV
309
        return this.actionsDirective.allChecked;
×
310
    }
311

312
    /**
313
     * Gets/Sets the value of the `id` attribute.
314
     *
315
     * @remarks
316
     * If not provided it will be automatically generated.
317
     * @example
318
     * ```html
319
     * <igx-column-actions [id]="'igx-actions-1'"></igx-column-actions>
320
     * ```
321
     */
322
    @HostBinding('attr.id')
323
    @Input()
324
    public get id(): string {
UNCOV
325
        return this._id;
×
326
    }
327
    public set id(value: string) {
328
        this._id = value;
×
329
    }
330

331
    /**
332
     * @hidden @internal
333
     */
334
    public get titleID() {
UNCOV
335
        return this.id + '_title';
×
336
    }
337

338
    /**
339
     * @hidden @internal
340
     */
UNCOV
341
    public trackChanges = (index, col) => col.field + '_' + this.actionsDirective.actionEnabledColumnsFilter(col, index, []);
×
342

343
    /**
344
     * @hidden @internal
345
     */
346
    public ngDoCheck() {
UNCOV
347
        if (this._differ) {
×
UNCOV
348
            const changes = this._differ.diff(this.grid?.columnList);
×
UNCOV
349
            if (changes) {
×
UNCOV
350
                this.pipeTrigger++;
×
351
            }
352
        }
353
    }
354

355
    /**
356
     * Unchecks all columns and performs the appropriate action.
357
     *
358
     * @example
359
     * ```typescript
360
     * this.columnActions.uncheckAllColumns();
361
     * ```
362
     */
363
    public uncheckAllColumns() {
UNCOV
364
        this.actionsDirective.uncheckAll();
×
365
    }
366

367
    /**
368
     * Checks all columns and performs the appropriate action.
369
     *
370
     * @example
371
     * ```typescript
372
     * this.columnActions.checkAllColumns();
373
     * ```
374
     */
375
    public checkAllColumns() {
UNCOV
376
        this.actionsDirective.checkAll();
×
377
    }
378

379
    /**
380
     * @hidden @internal
381
     */
382
    public toggleColumn(column: ColumnType) {
UNCOV
383
        this.actionsDirective.toggleColumn(column);
×
384

UNCOV
385
        this.columnToggled.emit({ column: column as any, checked: this.actionsDirective.columnChecked(column) });
×
386
    }
387
}
388

389
@Pipe({
390
    name: 'columnActionEnabled',
391
    standalone: true
392
})
393
export class IgxColumnActionEnabledPipe implements PipeTransform {
2✔
394

UNCOV
395
    constructor(@Inject(IgxColumnActionsComponent) protected columnActions: IgxColumnActionsComponent) { }
×
396

397
    public transform(
398
        collection: ColumnType[],
399
        actionFilter: (value: ColumnType, index: number, array: ColumnType[]) => boolean,
400
        _pipeTrigger: number
401
    ): ColumnType[] {
UNCOV
402
        if (!collection) {
×
403
            return collection;
×
404
        }
UNCOV
405
        let copy = collection.slice(0);
×
UNCOV
406
        if (copy.length && copy[0].grid.hasColumnLayouts) {
×
UNCOV
407
            copy = copy.filter(c => c.columnLayout);
×
408
        }
UNCOV
409
        if (actionFilter) {
×
UNCOV
410
            copy = copy.filter(actionFilter);
×
411
        }
412
        // Preserve the actionable collection for use in the component
UNCOV
413
        this.columnActions.actionableColumns = copy as any;
×
UNCOV
414
        return copy;
×
415
    }
416
}
417

418
@Pipe({
419
    name: 'filterActionColumns',
420
    standalone: true
421
})
422
export class IgxFilterActionColumnsPipe implements PipeTransform {
2✔
423

UNCOV
424
    constructor(@Inject(IgxColumnActionsComponent) protected columnActions: IgxColumnActionsComponent) { }
×
425

426
    public transform(collection: ColumnType[], filterCriteria: string, _pipeTrigger: number): ColumnType[] {
UNCOV
427
        if (!collection) {
×
428
            return collection;
×
429
        }
UNCOV
430
        let copy = collection.slice(0);
×
UNCOV
431
        if (filterCriteria && filterCriteria.length > 0) {
×
UNCOV
432
            const filterFunc = (c) => {
×
UNCOV
433
                const filterText = c.header || c.field;
×
UNCOV
434
                if (!filterText) {
×
435
                    return false;
×
436
                }
UNCOV
437
                return filterText.toLocaleLowerCase().indexOf(filterCriteria.toLocaleLowerCase()) >= 0 ||
×
438
                    (c.children?.some(filterFunc) ?? false);
439
            };
UNCOV
440
            copy = collection.filter(filterFunc);
×
441
        }
442
        // Preserve the filtered collection for use in the component
UNCOV
443
        this.columnActions.filteredColumns = copy as any;
×
UNCOV
444
        return copy;
×
445
    }
446
}
447

448
@Pipe({
449
    name: 'sortActionColumns',
450
    standalone: true
451
})
452
export class IgxSortActionColumnsPipe implements PipeTransform {
2✔
453

454
    public transform(collection: ColumnType[], displayOrder: ColumnDisplayOrder, _pipeTrigger: number): ColumnType[] {
UNCOV
455
        if (displayOrder === ColumnDisplayOrder.Alphabetical) {
×
UNCOV
456
            return collection.sort((a, b) => (a.header || a.field).localeCompare(b.header || b.field));
×
457
        }
UNCOV
458
        return collection;
×
459
    }
460
}
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