Skip to content

Commit d2dbc4a

Browse files
committed
fix(grid): emit the pagination events when paging is enabled runtime #9097
1 parent 8f99ecd commit d2dbc4a

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

Diff for: projects/igniteui-angular/src/lib/core/deprecateDecorators.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function DeprecateMethod(message: string): MethodDecorator {
3434
for (const x of arguments) {
3535
args.push(x);
3636
}
37-
return originalMethod.call(this, args);
37+
return originalMethod.call(this, ...args);
3838
};
3939

4040
return descriptor;

Diff for: projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

+40-33
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
import { getResizeObserver } from '../core/utils';
3333
import 'igniteui-trial-watermark';
3434
import { Subject, pipe, fromEvent, noop } from 'rxjs';
35-
import { takeUntil, first, filter, throttleTime, map, shareReplay } from 'rxjs/operators';
35+
import { takeUntil, first, filter, throttleTime, map, shareReplay, takeWhile } from 'rxjs/operators';
3636
import { cloneArray, flatten, mergeObjects, compareMaps, resolveNestedPath, isObject, PlatformUtil } from '../core/utils';
3737
import { GridColumnDataType } from '../data-operations/data-util';
3838
import { FilteringLogic, IFilteringExpression } from '../data-operations/filtering-expression.interface';
@@ -1234,8 +1234,8 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
12341234
public toolbar: QueryList<IgxGridToolbarComponent>;
12351235

12361236
/** @hidden @internal */
1237-
@ContentChild(IgxPaginatorComponent)
1238-
protected paginatorCmpt: IgxPaginatorComponent;
1237+
@ContentChildren(IgxPaginatorComponent)
1238+
protected paginatorCmpts: QueryList<IgxPaginatorComponent>;
12391239

12401240
/**
12411241
* @hidden @internal
@@ -1491,6 +1491,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
14911491
}
14921492

14931493
public set perPage(val: number) {
1494+
this._perPage = val;
14941495
if (this.paginator) {
14951496
this.paginator.perPage = val;
14961497
}
@@ -2616,7 +2617,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
26162617
*/
26172618
public set pagingState(value) {
26182619
this._pagingState = value;
2619-
if (this.paginator) {
2620+
if (this.paginator && !this._init) {
26202621
this.paginator.totalRecords = value.metadata.countRecords;
26212622
}
26222623
}
@@ -2852,7 +2853,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
28522853

28532854
/** @hidden @internal */
28542855
public get paginator() {
2855-
return this.paginatorCmpt;
2856+
return this.paginatorCmpts?.first;
28562857
}
28572858

28582859
/**
@@ -3510,30 +3511,31 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
35103511
public ngAfterContentInit() {
35113512
this.setupColumns();
35123513
this.toolbar.changes.pipe(takeUntil(this.destroy$), filter(() => !this._init)).subscribe(() => this.notifyChanges(true));
3513-
if (this.paginator) {
3514-
this.paginator.perPage = this.paginator.perPage || this._perPage;
3515-
this.paginator.pageChange.pipe(takeUntil(this.destroy$), filter(() => !this._init))
3516-
.subscribe((page: number) => {
3517-
this.pageChange.emit(page);
3518-
});
3519-
this.paginator.pagingDone.pipe(takeUntil(this.destroy$), filter(() => !this._init))
3520-
.subscribe((args: IPageEventArgs) => {
3521-
this.selectionService.clear(true);
3522-
this.pagingDone.emit({ previous: args.previous, current: args.current });
3523-
this.crudService.endEdit(false);
3524-
this.pipeTrigger++;
3525-
this.navigateTo(0);
3526-
this.notifyChanges();
3527-
});
3528-
this.paginator.perPageChange.pipe(takeUntil(this.destroy$), filter(() => !this._init))
3529-
.subscribe((perPage: number) => {
3530-
this.selectionService.clear(true);
3531-
this.perPageChange.emit(perPage);
3532-
this.page = 0;
3533-
this.crudService.endEdit(false);
3534-
this.notifyChanges();
3535-
});
3536-
}
3514+
this.paginatorCmpts.changes.pipe(takeUntil(this.destroy$), filter(() => !this._init)).subscribe(() => {
3515+
if (this.paginator) {
3516+
this.paginator.pageChange.pipe(takeWhile(() => !!this.paginator), filter(() => !this._init))
3517+
.subscribe((page: number) => {
3518+
this.pageChange.emit(page);
3519+
});
3520+
this.paginator.pagingDone.pipe(takeWhile(() => !!this.paginator), filter(() => !this._init))
3521+
.subscribe((args: IPageEventArgs) => {
3522+
this.selectionService.clear(true);
3523+
this.pagingDone.emit({ previous: args.previous, current: args.current });
3524+
this.crudService.endEdit(false);
3525+
this.pipeTrigger++;
3526+
this.navigateTo(0);
3527+
this.notifyChanges();
3528+
});
3529+
this.paginator.perPageChange.pipe(takeWhile(() => !!this.paginator), filter(() => !this._init))
3530+
.subscribe((perPage: number) => {
3531+
this.selectionService.clear(true);
3532+
this.perPageChange.emit(perPage);
3533+
this.page = 0;
3534+
this.crudService.endEdit(false);
3535+
this.notifyChanges();
3536+
});
3537+
}
3538+
});
35373539
if (this.actionStrip) {
35383540
this.actionStrip.menuOverlaySettings.outlet = this.outlet;
35393541
}
@@ -3628,7 +3630,12 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
36283630
});
36293631

36303632
// Keep the stream open for future subscribers
3631-
this.rendered$.pipe(takeUntil(this.destroy$)).subscribe(noop);
3633+
this.rendered$.pipe(takeUntil(this.destroy$)).subscribe(() => {
3634+
if (this.paginator) {
3635+
this.paginator.perPage = this._perPage;
3636+
this.paginator.totalRecords = this.totalRecords;
3637+
}
3638+
});
36323639
Promise.resolve().then(() => this.rendered.next(true));
36333640
}
36343641

@@ -6881,13 +6888,13 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
68816888
protected scrollTo(row: any | number, column: any | number, inCollection = this._filteredSortedUnpinnedData): void {
68826889
let delayScrolling = false;
68836890

6884-
if (this.paging && typeof (row) !== 'number') {
6891+
if (this.paginator && typeof (row) !== 'number') {
68856892
const rowIndex = inCollection.indexOf(row);
68866893
const page = Math.floor(rowIndex / this.perPage);
68876894

6888-
if (this.page !== page) {
6895+
if (this.paginator.page !== page) {
68896896
delayScrolling = true;
6890-
this.page = page;
6897+
this.paginator.page = page;
68916898
}
68926899
}
68936900

Diff for: projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class IgxHierarchicalGridComponent extends IgxHierarchicalGridBaseDirecti
202202

203203
/** @hidden @internal */
204204
public get paginator() {
205-
return this.paginatorCmpt || this.rootGrid.paginatorList.find((pg) =>
205+
return this.paginatorCmpts.first || this.rootGrid.paginatorList.find((pg) =>
206206
pg.nativeElement.offsetParent?.id === this.id);
207207
}
208208

0 commit comments

Comments
 (0)