Skip to content

Commit

Permalink
Merge pull request #19203 from abpframework/issue-19194
Browse files Browse the repository at this point in the history
Fix pagination issue in ExtensibleTableComponent
  • Loading branch information
oykuermann authored Mar 5, 2024
2 parents 5c77046 + fac19db commit ad9b702
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[rows]="data"
[count]="recordsTotal"
[list]="list"
[offset]="list?.page"
(page)="setPage($event)"
(activate)="tableActivate.emit($event)"
>
@if (actionsTemplate || (actionList.length && hasAtLeastOnePermittedAction)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ABP,
ConfigStateService,
CoreModule,
ConfigStateService,
getShortDateFormat,
getShortDateShortTimeFormat,
getShortTimeFormat,
Expand All @@ -13,9 +12,7 @@ import {
import {
AsyncPipe,
formatDate,
NgComponentOutlet,
NgFor,
NgIf,
NgComponentOutlet,
NgTemplateOutlet,
} from '@angular/common';
import {
Expand Down Expand Up @@ -175,7 +172,32 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
);
}

ngOnChanges({ data }: SimpleChanges) {
setPage({ offset }) {
this.list.page = offset;
}

ngOnChanges({ data, recordsTotal }: SimpleChanges) {
if (data?.currentValue.length < 1 && recordsTotal?.currentValue > 0) {
let maxPage = Math.floor(Number(recordsTotal?.currentValue / this.list.maxResultCount));

if(recordsTotal?.currentValue < this.list.maxResultCount) {
this.list.page = 0;
return;
}

if (recordsTotal?.currentValue % this.list.maxResultCount === 0) {
maxPage -= 1;
}

if (this.list.page < maxPage) {
this.list.page = this.list.page;
return;
}

this.list.page = maxPage;
return;
}

if (!data?.currentValue) return;

if (data.currentValue.length < 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class ListService<QueryParamsType = ABP.PageQueryParams | any> implements
this._query$.next({
filter: this._filter || undefined,
maxResultCount: this._maxResultCount,
skipCount: this._filter ? 0 : this._page * this._maxResultCount,
skipCount: this._page * this._maxResultCount,
sorting: this._sortOrder ? `${this._sortKey} ${this._sortOrder}` : undefined,
} as any as QueryParamsType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
};
}

private subscribeToPage() {
const sub = this.table.page.subscribe(({ offset }) => {
this.list.page = offset;
this.table.offset = offset;
});
this.subscription.add(sub);
}

private subscribeToSort() {
const sub = this.table.sort.subscribe(({ sorts: [{ prop, dir }] }) => {
if (prop === this.list.sortKey && this.list.sortOrder === 'desc') {
Expand Down Expand Up @@ -101,7 +93,6 @@ export class NgxDatatableListDirective implements OnChanges, OnDestroy, OnInit {
}

ngOnInit() {
this.subscribeToPage();
this.subscribeToSort();
}
}

0 comments on commit ad9b702

Please sign in to comment.