Skip to content

fix(grid): emit perPage once per operation #9373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions projects/igniteui-angular/src/lib/grids/grid-base.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1480,13 +1480,13 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
}

public set perPage(val: number) {
if (val < 0) {
if (val < 0 || val === this._perPage) {
return;
}
this.selectionService.clear(true);
this._perPage = val;
this.perPageChange.emit(this._perPage);
this.page = 0;
this.paginate(0);
this.crudService.endEdit(false);
this.notifyChanges();
}
Expand Down Expand Up @@ -4130,9 +4130,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
* ```
*/
public nextPage(): void {
if (!this.isLastPage) {
this.page += 1;
}
this.paginate(this._page + 1);
}

/**
Expand All @@ -4144,9 +4142,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
* ```
*/
public previousPage(): void {
if (!this.isFirstPage) {
this.page -= 1;
}
this.paginate(this._page - 1);
}

/**
Expand Down Expand Up @@ -4289,7 +4285,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
* @param val
*/
public paginate(val: number): void {
if (val < 0 || val > this.totalPages - 1) {
if (val < 0 || val > this.totalPages - 1 || val === this._page) {
return;
}

Expand Down
20 changes: 11 additions & 9 deletions projects/igniteui-angular/src/lib/paginator/paginator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class IgxPaginatorComponent extends DisplayDensityBase {

protected _page = 0;
protected _totalRecords: number;
protected _selectOptions;
protected _selectOptions = [5, 10, 15, 25, 50, 100, 500];
protected _perPage = 15;

private _resourceStrings = CurrentResourceStrings.PaginatorResStrings;
Expand Down Expand Up @@ -164,6 +164,9 @@ export class IgxPaginatorComponent extends DisplayDensityBase {
}

public set page(value: number) {
if (value < 0 || value > this.totalPages - 1 || value === this._page) {
return;
}
this._page = value;
this.pageChange.emit(this._page);
}
Expand All @@ -183,12 +186,15 @@ export class IgxPaginatorComponent extends DisplayDensityBase {
}

public set perPage(value: number) {
if (value < 0 || value === this._perPage) {
return;
}
this._perPage = Number(value);
this.perPageChange.emit(this._perPage);
this._selectOptions = this.sortUniqueOptions(this.defaultSelectValues, this._perPage);
this.totalPages = Math.ceil(this.totalRecords / this._perPage);
if (this.totalPages !== 0 && this.page >= this.totalPages) {
this.page = this.totalPages - 1;
this.paginate(this.totalPages - 1);
}
}

Expand Down Expand Up @@ -318,9 +324,7 @@ export class IgxPaginatorComponent extends DisplayDensityBase {
* @memberof IgxPaginatorComponent
*/
public nextPage(): void {
if (!this.isLastPage) {
this.page += 1;
}
this.paginate(this._page + 1);
}
/**
* Goes to the previous page of the `IgxPaginatorComponent`, if the paginator is not already at the first page.
Expand All @@ -331,9 +335,7 @@ export class IgxPaginatorComponent extends DisplayDensityBase {
* @memberof IgxPaginatorComponent
*/
public previousPage(): void {
if (!this.isFirstPage) {
this.page -= 1;
}
this.paginate(this._page - 1);
}
/**
* Goes to the desired page index.
Expand All @@ -345,7 +347,7 @@ export class IgxPaginatorComponent extends DisplayDensityBase {
* @memberof IgxPaginatorComponent
*/
public paginate(val: number): void {
if (val < 0 || val > this.totalPages - 1) {
if (val < 0 || val > this.totalPages - 1 || val === this._page) {
return;
}
this.page = val;
Expand Down