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

IgniteUI / igniteui-angular / 12910003674

22 Jan 2025 02:10PM CUT coverage: 91.609% (+0.01%) from 91.597%
12910003674

push

github

web-flow
Merge pull request #15285 from IgniteUI/mvenkov/use-passed-overlay-settings-18.2

Use provided in show method overlay settings - 18.2

12988 of 15222 branches covered (85.32%)

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

46 existing lines in 9 files now uncovered.

26321 of 28732 relevant lines covered (91.61%)

33978.84 hits per line

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

95.65
/projects/igniteui-angular/src/lib/paginator/paginator.component.ts
1
import { ChangeDetectorRef, Component, ContentChild, Directive, ElementRef, EventEmitter, Host, HostBinding, Input, Output, forwardRef } from '@angular/core';
2
import { IPageCancellableEventArgs, IPageEventArgs } from './paginator-interfaces';
3
import { IPaginatorResourceStrings, PaginatorResourceStringsEN } from '../core/i18n/paginator-resources';
4
import { OverlaySettings } from '../services/overlay/utilities';
5
import { IgxSelectItemComponent } from '../select/select-item.component';
6
import { FormsModule } from '@angular/forms';
7
import { IgxSelectComponent } from '../select/select.component';
8
import { IgxIconComponent } from '../icon/icon.component';
9
import { IgxRippleDirective } from '../directives/ripple/ripple.directive';
10
import { NgIf, NgFor } from '@angular/common';
11
import { getCurrentResourceStrings } from '../core/i18n/resources';
12
import { IgxIconButtonDirective } from '../directives/button/icon-button.directive';
13
import { IgxPaginatorToken } from './token';
14

15
@Directive({
16
    selector: '[igxPaginatorContent],igx-paginator-content',
17
    standalone: true
18
})
19
export class IgxPaginatorContentDirective {
2✔
20
    /**
21
     * @internal
22
     * @hidden
23
     */
24
    @HostBinding('class.igx-paginator-content')
25
    public cssClass = 'igx-paginator-content';
5✔
26
}
27

28
/* blazorElement */
29
/* mustUseNGParentAnchor */
30
/* wcElementTag: igc-paginator */
31
/* blazorIndirectRender */
32
/* singleInstanceIdentifier */
33
/* contentParent: GridBaseDirective */
34
/* contentParent: RowIsland */
35
/* contentParent: HierarchicalGrid */
36
/* jsonAPIManageCollectionInMarkup */
37
/**
38
 * Paginator component description
39
 * @igxParent IgxGridComponent, IgxTreeGridComponent, IgxHierarchicalGridComponent, IgxPivotGridComponent, *
40
 */
41
@Component({
42
    selector: 'igx-paginator',
43
    templateUrl: 'paginator.component.html',
44
    standalone: true,
45
    imports: [NgIf, forwardRef(() => IgxPageSizeSelectorComponent), forwardRef(() => IgxPageNavigationComponent)],
2,789✔
46
    providers: [
47
        { provide: IgxPaginatorToken, useExisting: IgxPaginatorComponent }
48
    ]
49
})
50
// switch IgxPaginatorToken to extends once density is dropped
51
export class IgxPaginatorComponent implements IgxPaginatorToken {
2✔
52

53
    /**
54
     * @hidden
55
     * @internal
56
     */
57
    @ContentChild(IgxPaginatorContentDirective)
58
    public customContent: IgxPaginatorContentDirective;
59

60
    /**
61
     * Emitted when `perPage` property value of the paginator is changed.
62
     *
63
     * @example
64
     * ```html
65
     * <igx-paginator (perPageChange)="onPerPageChange($event)"></igx-paginator>
66
     * ```
67
     * ```typescript
68
     * public onPerPageChange(perPage: number) {
69
     *   this.perPage = perPage;
70
     * }
71
     * ```
72
     */
73
    @Output()
74
    public perPageChange = new EventEmitter<number>();
237✔
75

76
    /**
77
     * Emitted after the current page is changed.
78
     *
79
     * @example
80
     * ```html
81
     * <igx-paginator (pageChange)="onPageChange($event)"></igx-paginator>
82
     * ```
83
     * ```typescript
84
     * public onPageChange(page: number) {
85
     *   this.currentPage = page;
86
     * }
87
     * ```
88
     */
89
    @Output()
90
    public pageChange = new EventEmitter<number>();
237✔
91

92
    /**
93
     * Emitted before paging is performed.
94
     *
95
     * @remarks
96
     * Returns an object consisting of the current and next pages.
97
     * @example
98
     * ```html
99
     * <igx-paginator (paging)="pagingHandler($event)"></igx-paginator>
100
     * ```
101
     */
102
    @Output()
103
    public paging = new EventEmitter<IPageCancellableEventArgs>();
237✔
104

105
    /**
106
     * Emitted after paging is performed.
107
     *
108
     * @remarks
109
     * Returns an object consisting of the previous and current pages.
110
     * @example
111
     * ```html
112
     * <igx-paginator (pagingDone)="pagingDone($event)"></igx-paginator>
113
     * ```
114
     */
115
    @Output()
116
    public pagingDone = new EventEmitter<IPageEventArgs>();
237✔
117

118
    /**
119
     * Total pages calculated from totalRecords and perPage
120
     */
121
    public totalPages: number;
122
    protected _page = 0;
237✔
123
    protected _totalRecords: number;
124
    protected _selectOptions = [5, 10, 15, 25, 50, 100, 500];
237✔
125
    protected _perPage = 15;
237✔
126

127
    private _resourceStrings = getCurrentResourceStrings(PaginatorResourceStringsEN);
237✔
128
    private _overlaySettings: OverlaySettings = {};
237✔
129
    private defaultSelectValues = [5, 10, 15, 25, 50, 100, 500];
237✔
130

131
    /** @hidden @internal */
132
    @HostBinding('class.igx-paginator')
133
    public cssClass = 'igx-paginator';
237✔
134

135
    /**
136
     * Gets/Sets the current page of the paginator.
137
     * The default is 0.
138
     * ```typescript
139
     * let page = this.paginator.page;
140
     * ```
141
     *
142
     * @memberof IgxPaginatorComponent
143
     */
144
    @Input()
145
    public get page() {
146
        return this._page;
96,613✔
147
    }
148

149
    public set page(value: number) {
150
        if (this._page === value || value < 0 || value > this.totalPages) {
425✔
151
            return;
298✔
152
        }
153
        const cancelEventArgs: IPageCancellableEventArgs = { current: this._page, next: value, cancel: false };
127✔
154
        const eventArgs: IPageEventArgs = { previous: this._page, current: value };
127✔
155

156
        this.paging.emit(cancelEventArgs);
127✔
157
        if (cancelEventArgs.cancel) {
127✔
158
            return;
2✔
159
        }
160
        this._page = value;
125✔
161
        this.pageChange.emit(this._page);
125✔
162

163
        this.pagingDone.emit(eventArgs);
125✔
164
    }
165

166
    /**
167
     * Gets/Sets the number of visible items per page in the paginator.
168
     * The default is 15.
169
     * ```typescript
170
     * let itemsPerPage = this.paginator.perPage;
171
     * ```
172
     *
173
     * @memberof IgxPaginatorComponent
174
     */
175
    @Input()
176
    public get perPage() {
177
        return this._perPage;
79,135✔
178
    }
179

180
    public set perPage(value: number) {
181
        if (value < 0 || this.perPage === value) {
180✔
182
            return;
1✔
183
        }
184
        this._perPage = Number(value);
179✔
185
        this.perPageChange.emit(this._perPage);
179✔
186
        this._selectOptions = this.sortUniqueOptions(this.defaultSelectValues, this._perPage);
179✔
187
        this.totalPages = Math.ceil(this.totalRecords / this._perPage);
179✔
188
        if (this.totalPages !== 0 && this.page >= this.totalPages) {
179✔
189
            this.page = this.totalPages - 1;
1✔
190
        }
191
    }
192

193
    /**
194
     * Sets the total records.
195
     * ```typescript
196
     * let totalRecords = this.paginator.totalRecords;
197
     * ```
198
     *
199
     * @memberof IgxPaginatorComponent
200
     */
201
    @Input()
202
    public get totalRecords() {
203
        return this._totalRecords;
712✔
204
    }
205

206
    public set totalRecords(value: number) {
207
        this._totalRecords = value;
519✔
208
        this.totalPages = Math.ceil(this.totalRecords / this.perPage);
519✔
209
        if (this.page > this.totalPages) {
519✔
210
            this.page = 0;
2✔
211
        }
212
        this.cdr.detectChanges();
519✔
213
    }
214

215
    /**
216
     * Sets custom options in the select of the paginator
217
     * ```typescript
218
     * let options = this.paginator.selectOptions;
219
     * ```
220
     *
221
     * @memberof IgxPaginatorComponent
222
     */
223
    @Input()
224
    public get selectOptions() {
225
        return this._selectOptions;
2,140✔
226
    }
227

228
    public set selectOptions(value: Array<number>) {
229
        this._selectOptions = this.sortUniqueOptions(value, this._perPage);
3✔
230
        this.defaultSelectValues = [...value];
3✔
231
    }
232

233
    /**
234
     * Sets custom OverlaySettings.
235
     * ```html
236
     * <igx-paginator [overlaySettings] = "customOverlaySettings"></igx-paginator>
237
     * ```
238
     */
239
    @Input()
240
    public get overlaySettings(): OverlaySettings {
241
        return this._overlaySettings;
2,139✔
242
    }
243

244
    public set overlaySettings(value: OverlaySettings) {
245
        this._overlaySettings = Object.assign({}, this._overlaySettings, value);
73✔
246
    }
247

248
    /* mustSetInCodePlatforms: WebComponents;Blazor;React */
249
    /**
250
     * An accessor that sets the resource strings.
251
     * By default it uses EN resources.
252
     */
253
    @Input()
254
    public set resourceStrings(value: IPaginatorResourceStrings) {
UNCOV
255
        this._resourceStrings = Object.assign({}, this._resourceStrings, value);
×
256
    }
257

258
    /**
259
     * An accessor that returns the resource strings.
260
     */
261
    public get resourceStrings(): IPaginatorResourceStrings {
262
        return this._resourceStrings;
12,836✔
263
    }
264

265
    constructor(private elementRef: ElementRef, private cdr: ChangeDetectorRef) { }
237✔
266

267
    /**
268
     * Returns if the current page is the last page.
269
     * ```typescript
270
     * const lastPage = this.paginator.isLastPage;
271
     * ```
272
     */
273
    public get isLastPage(): boolean {
274
        return this.page + 1 >= this.totalPages;
8,592✔
275
    }
276

277
    /**
278
     * Returns if the current page is the first page.
279
     * ```typescript
280
     * const lastPage = this.paginator.isFirstPage;
281
     * ```
282
     */
283
    public get isFirstPage(): boolean {
284
        return this.page === 0;
8,580✔
285
    }
286

287

288
    /**
289
     * Returns if the first pager buttons should be disabled
290
     * @hidden
291
     * @deprecated in version 18.1.0. Use the `isFirstPage` property instead.
292
     */
293
    public get isFirstPageDisabled(): boolean {
UNCOV
294
        return this.isFirstPage;
×
295
    }
296

297
    /**
298
     * Returns if the last pager buttons should be disabled
299
     * @hidden
300
     * @deprecated in version 18.1.0. Use the `isLastPage` property instead.
301
     */
302
    public get isLastPageDisabled(): boolean {
UNCOV
303
        return this.isLastPage;
×
304
    }
305

306
    public get nativeElement() {
307
        return this.elementRef.nativeElement;
91,501✔
308
    }
309

310
    /**
311
     * Goes to the next page of the `IgxPaginatorComponent`, if the paginator is not already at the last page.
312
     * ```typescript
313
     * this.paginator.nextPage();
314
     * ```
315
     *
316
     * @memberof IgxPaginatorComponent
317
     */
318
    public nextPage(): void {
319
        if (!this.isLastPage) {
25✔
320
            this.page += 1;
24✔
321
        }
322
    }
323
    /**
324
     * Goes to the previous page of the `IgxPaginatorComponent`, if the paginator is not already at the first page.
325
     * ```typescript
326
     * this.paginator.previousPage();
327
     * ```
328
     *
329
     * @memberof IgxPaginatorComponent
330
     */
331
    public previousPage(): void {
332
        if (!this.isFirstPage) {
13✔
333
            this.page -= 1;
12✔
334
        }
335
    }
336
    /**
337
     * Goes to the desired page index.
338
     * ```typescript
339
     * this.paginator.paginate(1);
340
     * ```
341
     *
342
     * @param val
343
     * @memberof IgxPaginatorComponent
344
     */
345
    public paginate(val: number): void {
346
        if (val < 0 || val > this.totalPages - 1) {
34✔
347
            return;
4✔
348
        }
349
        this.page = val;
30✔
350
    }
351

352
    private sortUniqueOptions(values: Array<number>, newOption: number): number[] {
353
        return Array.from(new Set([...values, newOption])).sort((a, b) => a - b);
1,360✔
354
    }
355
}
356

357

358
@Component({
359
    selector: 'igx-page-size',
360
    templateUrl: 'page-size-selector.component.html',
361
    standalone: true,
362
    imports: [IgxSelectComponent, FormsModule, NgFor, IgxSelectItemComponent]
363
})
364
export class IgxPageSizeSelectorComponent {
2✔
365
    /**
366
     * @internal
367
     * @hidden
368
     */
369
    @HostBinding('class.igx-page-size')
370
    public cssClass = 'igx-page-size';
230✔
371

372
    constructor(@Host() public paginator: IgxPaginatorComponent) { }
230✔
373
}
374

375

376
@Component({
377
    selector: 'igx-page-nav',
378
    templateUrl: 'pager.component.html',
379
    standalone: true,
380
    imports: [IgxRippleDirective, IgxIconComponent, IgxIconButtonDirective]
381
})
382
export class IgxPageNavigationComponent {
2✔
383
    /**
384
     * @internal
385
     * @hidden
386
     */
387
    @HostBinding('class.igx-page-nav')
388
    public cssClass = 'igx-page-nav';
230✔
389

390
    /**
391
     * Sets the `role` attribute of the element.
392
     */
393
    @HostBinding('attr.role')
394
    @Input()
395
    public role = 'navigation';
230✔
396

397
    constructor(
398
        @Host()
399
        public paginator: IgxPaginatorComponent) { }
230✔
400
}
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