Skip to content

Commit

Permalink
fix(pagination): current page index
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjalmers committed Oct 20, 2024
1 parent cf47090 commit 29f8809
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions projects/core/src/lib/core.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {
} from './utilities/utilities';
import { TableRow } from './models/table-row.interface';
import { GtOrder, GtSortOrder } from './models/table-sort.interface';
import { TableMeta } from './models/table-meta.interface';
import {
GtPageChangeEvent,
GtRowSelectEvent,
Expand Down Expand Up @@ -423,7 +422,7 @@ export class CoreComponent implements OnDestroy {
shareReplay(1)
);

table$: Observable<TableMeta> = combineLatest([
table$ = combineLatest([
this.data$,
this.tableConfig$,
this._pagingInfo$,
Expand Down Expand Up @@ -490,19 +489,18 @@ export class CoreComponent implements OnDestroy {

private _tableInfo$ = new BehaviorSubject<TableInfo | undefined>(undefined);

private _currentPaginationIndex$: BehaviorSubject<number> =
new BehaviorSubject(0);
private _currentPaginationIndex$ = new BehaviorSubject(0);
currentPaginationIndex$ = combineLatest([
this._currentPaginationIndex$,
this.table$,
]).pipe(
map(([page, table]: any) => {
map(([page, table]) => {
// determine last page
const lastPage =
Math.ceil(
table.info.records /
(table.info.recordLength ??
(table.config?.pagination?.length || table.info.records))
table.info.numberOfRecords /
(table.info.pageSize ??
(table.config?.pagination?.length || table.info.numberOfRecords))
) - 1;
// determine min/max position
return +page < 0 ? 0 : +page > lastPage ? lastPage : +page;
Expand Down

0 comments on commit 29f8809

Please sign in to comment.