diff --git a/angular/demo/src/app/samples/pagination/hash.route.ts b/angular/demo/src/app/samples/pagination/hash.route.ts new file mode 100644 index 0000000000..6a7b6ad3b0 --- /dev/null +++ b/angular/demo/src/app/samples/pagination/hash.route.ts @@ -0,0 +1,31 @@ +import {AgnosUIAngularModule, toAngularSignal} from '@agnos-ui/angular'; +import {hash$} from '@agnos-ui/common/utils'; +import {Component, computed} from '@angular/core'; +@Component({ + standalone: true, + imports: [AgnosUIAngularModule], + template: ` +
A pagination with hrefs provided for each pagination element:
++ Page hash: {{ '#' + hash() }} +
+ + `, +}) +export default class HashPaginationComponent { + hash = toAngularSignal(hash$); + + pageNumber = computed(() => +(this.hash().split('#')[1] ?? 4)); + + pageLink = (currentPage: number) => `#${this.hash().split('#')[0]}#${currentPage}`; + + pageChange = (currentPage: number) => (location.hash = `#${this.hash().split('#')[0]}#${currentPage}`); +} diff --git a/angular/lib/src/components/pagination/pagination.component.ts b/angular/lib/src/components/pagination/pagination.component.ts index ac3281c8bc..654041b2e6 100644 --- a/angular/lib/src/components/pagination/pagination.component.ts +++ b/angular/lib/src/components/pagination/pagination.component.ts @@ -121,8 +121,8 @@ export class PaginationPagesDirective { @@ -165,8 +165,8 @@ const defaultConfig: PartialThe pagination widget is fully customizable, from the page numbers to the arrows.
+ The example shows the pagination widget with hrefs provided for each page element.
+ The hrefs customization is based on pageLink input. This receives a custom function which computes the href using the received page
+ number and the location hash. On the pageChange output event, the location hash is updated with the href of the current page element.
+ This strategy permits navigations in current browser tab, and opening a page in new tabs using the customized href.
+
+ "A pagination with hrefs provided for each pagination element:" +
++ "Page hash:" + + "#/pagination/hash" + +
+ +A pagination with hrefs provided for each pagination element:
++ Page hash: {'#' + hash} +
+A pagination with hrefs provided for each pagination element:
++ Page hash: {'#' + $hash$} +
+