pagination

Pagination with page navigation, next and previous links.

PreviousNext
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';

import { ZardPaginationImports } from '../pagination.imports';

@Component({
  selector: 'z-demo-pagination-preview',
  imports: [ZardPaginationImports],
  template: `
    <z-pagination [zTotal]="totalPages" [(zPageIndex)]="currentPage" [zContent]="content" />

    <ng-template #content>
      <ul z-pagination-content>
        <li z-pagination-item>
          <z-pagination-previous (click)="goToPrevious()" [zDisabled]="currentPage() === 1" />
        </li>

        @for (page of pages(); track page) {
          <li z-pagination-item>
            <button type="button" z-pagination-button [zActive]="page === currentPage()" (click)="goToPage(page)">
              <span class="sr-only">To page</span>
              {{ page }}
            </button>
          </li>
        }

        <li z-pagination-item>
          <z-pagination-ellipsis />
        </li>

        <li z-pagination-item>
          <z-pagination-next (click)="goToNext()" [zDisabled]="currentPage() === totalPages" />
        </li>
      </ul>
    </ng-template>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoPaginationPreviewComponent {
  readonly totalPages = 3;
  readonly currentPage = signal(2);

  readonly pages = signal<number[]>(Array.from({ length: this.totalPages }, (_, i) => i + 1));

  goToPage(page: number) {
    this.currentPage.set(page);
  }

  goToPrevious() {
    if (this.currentPage() > 1) {
      this.currentPage.update(p => p - 1);
    }
  }

  goToNext() {
    if (this.currentPage() < this.totalPages) {
      this.currentPage.update(p => p + 1);
    }
  }
}

Installation

Copy
npx zard-cli@latest add pagination

Usage

import { ZardPaginationImports } from '@/shared/components/pagination/pagination.imports';
Copy
<z-pagination [zTotal]="100" [zPageSize]="10"></z-pagination>
Copy

Examples

simple

A simple pagination with only page numbers.

import { ChangeDetectionStrategy, Component } from '@angular/core';

import { ZardPaginationImports } from '../pagination.imports';

@Component({
  selector: 'z-demo-pagination-simple',
  imports: [ZardPaginationImports],
  template: `
    <z-pagination [zTotal]="5" [(zPageIndex)]="currentPage" zSimple />
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoPaginationSimpleComponent {
  protected currentPage = 2;
}

icons only

Use just the previous and next buttons without page numbers. This is useful for data tables with a rows per page selector.

import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';

import { ZardFieldImports } from '@/shared/components/field';
import { ZardPaginationImports } from '@/shared/components/pagination';
import { ZardSelectImports } from '@/shared/components/select';

@Component({
  selector: 'z-demo-pagination-iconsonly',
  imports: [ZardPaginationImports, ZardFieldImports, ZardSelectImports],
  template: `
    <div class="flex w-full justify-around">
      <div class="flex w-fit gap-4">
        <div z-field class="flex-row items-center">
          <label z-field-label for="select-rows-per-page" class="min-w-max">Rows Per Page</label>
          <z-select id="select-rows-per-page" zSize="sm" [(zValue)]="perPage" class="min-w-20">
            <z-select-item zValue="10">10</z-select-item>
            <z-select-item zValue="25">25</z-select-item>
            <z-select-item zValue="50">50</z-select-item>
            <z-select-item zValue="100">100</z-select-item>
          </z-select>
        </div>
        <z-pagination [zTotal]="totalPages()" [(zPageIndex)]="currentPage" [zContent]="content" />
      </div>
    </div>

    <ng-template #content>
      <ul z-pagination-content>
        <li z-pagination-item>
          <z-pagination-previous (click)="goToPrevious()" [zDisabled]="currentPage() === 1" />
        </li>

        <li z-pagination-item>
          <z-pagination-next (click)="goToNext()" [zDisabled]="currentPage() === totalPages()" />
        </li>
      </ul>
    </ng-template>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoPaginationIconsOnlyComponent {
  private totalItems = 350;

  readonly currentPage = signal(1);
  readonly perPage = signal('25');
  readonly totalPages = computed(() => Math.ceil(this.totalItems / parseInt(this.perPage())));

  goToPrevious() {
    if (this.currentPage() > 1) {
      this.currentPage.update(p => p - 1);
    }
  }

  goToNext() {
    if (this.currentPage() < this.totalPages()) {
      this.currentPage.update(p => p + 1);
    }
  }
}

API Reference

z-paginationComponent

Pagination component with previous, next, and numbered page navigation. Supports two-way binding via [(zPageIndex)] model signal.

PropertyDescriptionTypeDefault
[class] Custom CSS classes string ''
[zAriaLabel] Use a unique, descriptive ARIA label for the element. string Pagination
[zContent] Custom pagination structure TemplateRef<void> | undefined undefined
[zDisabled] Disables pagination interaction boolean false
[(zPageIndex)] Current page index number 1
[zSimple] A simple pagination with only page numbers. boolean false
[zSize] Button size 'icon' | 'icon-xs' | 'icon-sm' | 'icon-lg' 'icon'
[zTotal] Total number of pages number 1

ul[z-pagination-content]Component

Container (unordered list) for pagination content (buttons and ellipsis).

PropertyDescriptionTypeDefault
[class] Custom CSS classes string ''

li[z-pagination-item]Component

Wraps a pagination button or ellipsis as li element of container.

PropertyDescriptionTypeDefault

button[z-pagination-button], a[z-pagination-button]Component

Pagination button with support for active and disabled states.

PropertyDescriptionTypeDefault
[class] Custom CSS classes string ''
[zActive] Whether the button is currently active boolean false
[zDisabled] Whether the button is disabled boolean false
[zSize] Button size 'icon' | 'icon-xs' | 'icon-sm' | 'icon-lg' 'icon'

z-pagination-previousComponent

Button to navigate to the previous page.

PropertyDescriptionTypeDefault
[class] Custom CSS classes string ''
[zDisabled] Whether the button is disabled boolean false
[zSize] Button size 'default' | 'xs' | 'sm' | 'lg' 'default'

z-pagination-nextComponent

Button to navigate to the next page.

PropertyDescriptionTypeDefault
[class] Custom CSS classes string ''
[zDisabled] Whether the button is disabled boolean false
[zSize] Button size 'default' | 'xs' | 'sm' | 'lg' 'default'

z-pagination-ellipsisComponent

Visual ellipsis ("...") for omitted pages.

PropertyDescriptionTypeDefault
[class] Custom CSS classes string ''
github iconwhatsapp icondiscord iconX icon

Made with in Brazil. Open source and available on GitHub .