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

IgniteUI / igniteui-angular / 13548823408

26 Feb 2025 04:36PM CUT coverage: 91.555% (-0.04%) from 91.599%
13548823408

Pull #15223

github

web-flow
Merge 3ac8087aa into 786685675
Pull Request #15223: fix(pivot-grid): added createRow method for grid based events - 19.0

12997 of 15250 branches covered (85.23%)

0 of 18 new or added lines in 2 files covered. (0.0%)

135 existing lines in 23 files now uncovered.

26344 of 28774 relevant lines covered (91.55%)

34046.37 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
    imports: [NgIf, forwardRef(() => IgxPageSizeSelectorComponent), forwardRef(() => IgxPageNavigationComponent)],
2,796✔
45
    providers: [
46
        { provide: IgxPaginatorToken, useExisting: IgxPaginatorComponent }
47
    ]
48
})
49
// switch IgxPaginatorToken to extends once density is dropped
50
export class IgxPaginatorComponent implements IgxPaginatorToken {
2✔
51

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

286

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

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

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

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

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

356

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

370
    constructor(@Host() public paginator: IgxPaginatorComponent) { }
230✔
371
}
372

373

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

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

394
    constructor(
395
        @Host()
396
        public paginator: IgxPaginatorComponent) { }
230✔
397
}
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