diff --git a/libs/features/conditions/src/select-conditions/select-conditions.component.html b/libs/features/conditions/src/select-conditions/select-conditions.component.html index 3809c1403a9..ffb314bf4cc 100644 --- a/libs/features/conditions/src/select-conditions/select-conditions.component.html +++ b/libs/features/conditions/src/select-conditions/select-conditions.component.html @@ -79,6 +79,8 @@ [limit]="DTCFG.limit" [selectionType]="DTCFG.selectionType" (select)="onSelect($event)" + [offset]="selectService.pageOffset" + (page)="onPage($event)" > diff --git a/libs/features/creature/src/select-creature/select-creature.component.html b/libs/features/creature/src/select-creature/select-creature.component.html index b14fbcddd9e..a621890f3ce 100644 --- a/libs/features/creature/src/select-creature/select-creature.component.html +++ b/libs/features/creature/src/select-creature/select-creature.component.html @@ -52,6 +52,8 @@ [rowHeight]="DTCFG.rowHeight" [limit]="DTCFG.limit" [selectionType]="DTCFG.selectionType" + [offset]="selectService.pageOffset" + (page)="onPage($event)" (select)="selectService.onSelect($event)" > diff --git a/libs/features/gameobject/src/select-gameobject/select-gameobject.component.html b/libs/features/gameobject/src/select-gameobject/select-gameobject.component.html index 8cbfb50b15b..de3c8a806cc 100644 --- a/libs/features/gameobject/src/select-gameobject/select-gameobject.component.html +++ b/libs/features/gameobject/src/select-gameobject/select-gameobject.component.html @@ -59,6 +59,8 @@ [limit]="DTCFG.limit" [selectionType]="DTCFG.selectionType" (select)="selectService.onSelect($event)" + [offset]="selectService.pageOffset" + (page)="onPage($event)" > diff --git a/libs/features/gossip/src/select-gossip/select-gossip.component.html b/libs/features/gossip/src/select-gossip/select-gossip.component.html index 7e5d756175a..ab7f04d1c1d 100644 --- a/libs/features/gossip/src/select-gossip/select-gossip.component.html +++ b/libs/features/gossip/src/select-gossip/select-gossip.component.html @@ -47,6 +47,8 @@ [limit]="DTCFG.limit" [selectionType]="DTCFG.selectionType" (select)="selectService.onSelect($event)" + [offset]="selectService.pageOffset" + (page)="onPage($event)" > diff --git a/libs/features/item/src/select-item/select-item.component.html b/libs/features/item/src/select-item/select-item.component.html index 5ee48186f0f..6f172db211b 100644 --- a/libs/features/item/src/select-item/select-item.component.html +++ b/libs/features/item/src/select-item/select-item.component.html @@ -47,6 +47,8 @@ [limit]="DTCFG.limit" [selectionType]="DTCFG.selectionType" (select)="selectService.onSelect($event)" + [offset]="selectService.pageOffset" + (page)="onPage($event)" > diff --git a/libs/features/other-loots/src/select-loot.component.html b/libs/features/other-loots/src/select-loot.component.html index fe6d0e6935d..0bd0f07ab91 100644 --- a/libs/features/other-loots/src/select-loot.component.html +++ b/libs/features/other-loots/src/select-loot.component.html @@ -45,6 +45,8 @@ [limit]="DTCFG.limit" [selectionType]="DTCFG.selectionType" (select)="selectService.onSelect($event)" + [offset]="selectService.pageOffset" + (page)="onPage($event)" > diff --git a/libs/features/quest/src/select-quest/select-quest.component.html b/libs/features/quest/src/select-quest/select-quest.component.html index 78154514b93..491555ab800 100644 --- a/libs/features/quest/src/select-quest/select-quest.component.html +++ b/libs/features/quest/src/select-quest/select-quest.component.html @@ -47,6 +47,8 @@ [limit]="DTCFG.limit" [selectionType]="DTCFG.selectionType" (select)="selectService.onSelect($event)" + [offset]="selectService.pageOffset" + (page)="onPage($event)" > diff --git a/libs/features/spell/src/select-spell/select-spell.component.html b/libs/features/spell/src/select-spell/select-spell.component.html index 3081aa58e17..5806c25c27a 100644 --- a/libs/features/spell/src/select-spell/select-spell.component.html +++ b/libs/features/spell/src/select-spell/select-spell.component.html @@ -68,6 +68,8 @@ [limit]="DTCFG.limit" [selectionType]="DTCFG.selectionType" (select)="selectService.onSelect($event)" + [offset]="selectService.pageOffset" + (page)="onPage($event)" > diff --git a/libs/shared/base-abstract-classes/src/components/editors/select-complex-key.component.ts b/libs/shared/base-abstract-classes/src/components/editors/select-complex-key.component.ts index 066816364fd..11161c68058 100644 --- a/libs/shared/base-abstract-classes/src/components/editors/select-complex-key.component.ts +++ b/libs/shared/base-abstract-classes/src/components/editors/select-complex-key.component.ts @@ -1,5 +1,5 @@ import { ComplexKeyHandlerService } from '../../service/handlers/complex-key.handler.service'; -import { TableRow, WIKI_BASE_URL } from '@keira/shared/constants'; +import { DataTablePageEvent, TableRow, WIKI_BASE_URL } from '@keira/shared/constants'; import { DTCFG } from '@keira/shared/config'; import { ChangeDetectorRef, inject } from '@angular/core'; import { SearchService } from '../../service/select/search.service'; @@ -25,4 +25,8 @@ export abstract class SelectComplexKeyComponent { onSearch(): void { this.selectService.onSearch(this.changeDetectorRef); } + + onPage(event: DataTablePageEvent): void { + this.selectService.pageOffset = event.offset; + } } diff --git a/libs/shared/base-abstract-classes/src/components/editors/select.component.ts b/libs/shared/base-abstract-classes/src/components/editors/select.component.ts index 2c071811f49..46affa11f23 100644 --- a/libs/shared/base-abstract-classes/src/components/editors/select.component.ts +++ b/libs/shared/base-abstract-classes/src/components/editors/select.component.ts @@ -1,6 +1,6 @@ /* istanbul ignore file */ // TODO: fix coverage import { ChangeDetectorRef, inject } from '@angular/core'; -import { TableRow } from '@keira/shared/constants'; +import { DataTablePageEvent, TableRow } from '@keira/shared/constants'; import { SelectService } from '../../service/select/select.service'; import { MysqlQueryService } from '@keira/shared/db-layer'; import { HandlerService } from '../../service/handlers/handler.service'; @@ -21,4 +21,8 @@ export abstract class SelectComponent { onSearch(): void { this.selectService.onSearch(this.changeDetectorRef); } + + onPage(event: DataTablePageEvent): void { + this.selectService.pageOffset = event.offset; + } } diff --git a/libs/shared/base-abstract-classes/src/service/select/search.service.ts b/libs/shared/base-abstract-classes/src/service/select/search.service.ts index bf58d87cf3b..83d5bcadaef 100644 --- a/libs/shared/base-abstract-classes/src/service/select/search.service.ts +++ b/libs/shared/base-abstract-classes/src/service/select/search.service.ts @@ -7,6 +7,7 @@ import { ModelForm, ModelNestedForm, SubscriptionHandler } from '@keira/shared/u export abstract class SearchService extends SubscriptionHandler { query: string; rows: T[] | undefined; + pageOffset = 0; // Initialize to the first page fields: FormGroup> = new FormGroup({} as any); queryForm = new FormGroup>>({ limit: new FormControl(50) as any, // TODO: fix typing @@ -43,6 +44,9 @@ export abstract class SearchService extends SubscriptionHand } onSearch(changeDetectorRef: ChangeDetectorRef): void { + // Reset to the first page + this.pageOffset = 0; + this.subscriptions.push( this.queryService.query(this.query).subscribe((data) => { this.rows = data as T[]; diff --git a/libs/shared/constants/src/types/general.ts b/libs/shared/constants/src/types/general.ts index 3f223bd79cb..0f0e025b71a 100644 --- a/libs/shared/constants/src/types/general.ts +++ b/libs/shared/constants/src/types/general.ts @@ -48,3 +48,11 @@ export interface FieldDefinition { name: string; tooltip: string; } + +// Defines a type for the ngx datatable page event +export interface DataTablePageEvent { + count: number; // Total number of rows in the table + pageSize: number; // Number of rows per page (same as the 'limit' property) + limit: number; // Maximum rows displayed per page (also same as 'pageSize') + offset: number; // Current page index (0-based) +}