# Paginator

A pagination bar with first, previous, numbered, next and last page buttons, an optional page-size select and a range report. Use it for lists, grids and server-side data; `vig-table` embeds one with its `paginator` input.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-paginator`
- Source: [libs/ui/src/lib/molecules/paginator/paginator.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/molecules/paginator/paginator.ts)

```typescript title="Import"
import { Paginator } from '@vigdx/ui/paginator';
```

## Basic

State lives in two models: `first`, the zero-based index of the first record, and `rows`, the page size. Two-way bind `[(first)]` and slice your data with it; `totalRecords` is required.

```typescript title="paginator-basic.ts"
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { Paginator } from '@vigdx/ui/paginator';

const ORDERS = Array.from({ length: 23 }, (_, i) => `Order #${20400 + i}`);

@Component({
  selector: 'app-paginator-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Paginator],
  template: `
    <div class="flex max-w-xl flex-col gap-4">
      <ul class="divide-y divide-border-subtle rounded-card border border-border text-sm">
        @for (order of page(); track order) {
          <li class="px-4 py-2 text-foreground">{{ order }}</li>
        }
      </ul>
      <vig-paginator
        ariaLabel="Orders pages"
        [(first)]="first"
        [rows]="5"
        [totalRecords]="orders.length"
      />
    </div>
  `,
})
export class PaginatorBasicDemo {
  protected readonly orders = ORDERS;
  protected readonly first = signal(0);
  protected readonly page = computed(() => this.orders.slice(this.first(), this.first() + 5));
}
```

## Page size

`rowsPerPageOptions` adds a page-size select. Changing it updates `rows` and returns to the first page; bind both models to drive a server request.

```typescript title="paginator-page-size.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { Paginator } from '@vigdx/ui/paginator';

@Component({
  selector: 'app-paginator-page-size',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Paginator],
  template: `
    <vig-paginator
      ariaLabel="Customer pages"
      [(first)]="first"
      [(rows)]="rows"
      [totalRecords]="482"
      [rowsPerPageOptions]="[10, 25, 50, 100]"
    />
    <p class="text-sm text-muted-foreground">
      Request: <code>offset={{ first() }}&amp;limit={{ rows() }}</code>
    </p>
  `,
})
export class PaginatorPageSizeDemo {
  protected readonly first = signal(0);
  protected readonly rows = signal(25);
}
```

## Sizes

`size` is `sm` (default, 28px controls on 12px text) or `md` (32px controls on 14px text).

```typescript title="paginator-sizes.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Paginator } from '@vigdx/ui/paginator';

@Component({
  selector: 'app-paginator-sizes',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Paginator],
  template: `
    <vig-paginator ariaLabel="Small pagination" [first]="60" [totalRecords]="480" />
    <vig-paginator ariaLabel="Medium pagination" size="md" [first]="60" [totalRecords]="480" />
  `,
})
export class PaginatorSizesDemo {}
```

## Range report

`reportTemplate` formats the report with the `{first}`, `{last}`, `{total}`, `{page}` and `{pageCount}` placeholders. `reportPosition` places it at the `start` (default, split layout) or `end`.

```typescript title="paginator-report.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Paginator } from '@vigdx/ui/paginator';

@Component({
  selector: 'app-paginator-report',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Paginator],
  template: `
    <vig-paginator
      ariaLabel="Search results pages"
      [totalRecords]="137"
      reportTemplate="Showing {first}–{last} of {total} results"
    />
    <vig-paginator
      ariaLabel="Gallery pages"
      [rows]="12"
      [totalRecords]="96"
      reportPosition="end"
      reportTemplate="Page {page} of {pageCount}"
    />
  `,
})
export class PaginatorReportDemo {}
```

## Disabled

`disabled` turns off every button and the page-size select, e.g. while a page is loading.

```typescript title="paginator-disabled.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Paginator } from '@vigdx/ui/paginator';

@Component({
  selector: 'app-paginator-disabled',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Paginator],
  template: `
    <vig-paginator
      ariaLabel="Archive pages"
      [disabled]="true"
      [first]="20"
      [totalRecords]="120"
      [rowsPerPageOptions]="[10, 20, 50]"
    />
  `,
})
export class PaginatorDisabledDemo {}
```

## Labels

Every accessible name and the report are inputs for translations; `pageAriaLabel` replaces `{0}` with the page number. Set app-wide defaults through the kit's labels instead of per instance.

```typescript title="paginator-labels.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Paginator } from '@vigdx/ui/paginator';

@Component({
  selector: 'app-paginator-labels',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Paginator],
  template: `
    <vig-paginator
      [totalRecords]="245"
      [rowsPerPageOptions]="[10, 25, 50]"
      ariaLabel="Seitennavigation"
      firstPageAriaLabel="Erste Seite"
      prevPageAriaLabel="Vorherige Seite"
      nextPageAriaLabel="Nächste Seite"
      lastPageAriaLabel="Letzte Seite"
      pageAriaLabel="Seite {0}"
      rowsPerPageAriaLabel="Einträge pro Seite"
      reportTemplate="{first}–{last} von {total}"
    />
  `,
})
export class PaginatorLabelsDemo {}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="paginator"][data-part="report"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="paginator"]`

| Part | Element | data-state |
| --- | --- | --- |
| `report` | The range report. |   |
| `pages` | Group of the navigation and page buttons. |   |
| `first` | First page button. |   |
| `prev` | Previous page button. |   |
| `page` | A page number button (`aria-current="page"`). | `active` |
| `next` | Next page button. |   |
| `last` | Last page button. |   |
| `jump` | The jump-to-page field (`showJumpToPage`). |   |
| `rows-per-page` | The page-size `<select>`. |   |
| `rows-per-page-option` | An `<option>` of the page-size select. |   |

## Accessibility

- The bar is a `<nav>` landmark named by `ariaLabel` (“Pagination” by default). With several paginators on one page, give each a distinct name.
- All controls are native buttons and a native `<select>`, reachable with Tab and activated with Enter or Space.
- Icon buttons are labelled (“First page”, “Previous page”…), numbered buttons read “Page 3”, and the current page carries `aria-current="page"`.
- Buttons that lead nowhere, such as Next on the last page, are `aria-disabled` rather than `disabled`: they stay focusable, so focus is not lost when the boundary is reached, and ignore activation. After a page change, consider moving focus to the top of the updated content.

## API

### Paginator

Selector: `vig-paginator` · Kind: component

Standalone pagination bar (PrimeNG p-paginator territory). State lives in the `first`/`rows` models so it can be two-way bound by vig-table or used directly. The report is a function of `PaginatorReport`, or a string with {first}, {last}, {total}, {page} and {pageCount} placeholders.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `ariaLabel` | `string \| undefined` | `undefined` | — |
| `disabled` | `boolean` | `false` | — |
| `first` (model) | `number` | `0` | Zero-based index of the first record on the current page. |
| `firstPageAriaLabel` | `string \| undefined` | `undefined` | — |
| `jumpToPageAriaLabel` | `string \| undefined` | `undefined` | Name of the jump-to-page field (i18n). |
| `lastPageAriaLabel` | `string \| undefined` | `undefined` | — |
| `nextPageAriaLabel` | `string \| undefined` | `undefined` | — |
| `pageAriaLabel` | `string \| ((page: number) => string) \| undefined` | `undefined` | Name of a page button: a function of the 1-based page number, or a string where `{0}` is replaced with it. |
| `prevPageAriaLabel` | `string \| undefined` | `undefined` | — |
| `reportPosition` | `PaginatorReportPosition` | `'start'` | `start` splits the bar: the range report on the left, the controls on the right. `end` packs everything to the right with the report last. |
| `reportTemplate` | `string \| ((report: PaginatorReport) => string) \| undefined` | `undefined` | The range report: a function of the `PaginatorReport` numbers, e.g. `(r) => r.first + '–' + r.last + ' of ' + r.total`, or a string with `{first}`, `{last}`, `{total}`, `{page}` and `{pageCount}` placeholders. |
| `rows` (model) | `number` | `10` | Page size. |
| `rowsPerPageAriaLabel` | `string \| undefined` | `undefined` | — |
| `rowsPerPageOptions` | `readonly number[]` | `[]` | Shown as a page-size dropdown when non-empty. |
| `showJumpToPage` | `boolean` | `false` | Adds a number field that jumps straight to a typed page (applied on change or Enter). |
| `size` | `PaginatorSize` | `'sm'` | `sm` keeps 28px controls on 12px text; `md` uses 32px controls on 14px text. |
| `totalRecords` (required) | `number` | — | — |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `firstChange` | `number` | Zero-based index of the first record on the current page. |
| `rowsChange` | `number` | Page size. |
