---
title: "Pagination"
description: "Навигационный компонент с кнопками или ссылками для постраничного вывода."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/pagination"
---
# Pagination

> Навигационный компонент с кнопками или ссылками для постраничного вывода.

## Использование

Пропс `default-page` или директива `v-model:page` управляет текущей страницей.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" />
</template>
```

> [!NOTE]
> Pagination использует [`Button`](https://b24-ui.bx-shef.by/raw/docs/components/button.md) для отображения страниц; пропсы [`color`](#color) и [`size`](#size) задают их стиль.

### Всего

Пропс `total` задаёт общее число элементов в списке.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" />
</template>
```

### Элементов на странице

Пропс `items-per-page` задаёт число элементов на странице. По умолчанию `10`.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :items-per-page="20" :total="100" />
</template>
```

### Число соседних страниц

Пропс `sibling-count` задаёт, сколько соседних страниц показывать. По умолчанию `2`.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :sibling-count="1" :total="100" />
</template>
```

### Крайние страницы

Пропс `show-edges` всегда показывает многоточие, первую и последнюю страницы. По умолчанию `false`.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" show-edges :sibling-count="1" :total="100" />
</template>
```

### Кнопки управления

Пропс `show-controls` показывает кнопки «первая», «предыдущая», «следующая» и «последняя». По умолчанию `true`.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :show-controls="false" show-edges :total="100" />
</template>
```

### Цвет

Пропс `color` задаёт цвет неактивных элементов управления. По умолчанию `air-secondary-no-accent`.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" color="air-tertiary-no-accent" :total="100" />
</template>
```

### Цвет активной страницы

Пропс `active-color` задаёт цвет активного элемента управления. По умолчанию `air-primary`.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" active-color="air-primary-copilot" :total="100" />
</template>
```

### Размер

Пропс `size` задаёт размер элементов управления. По умолчанию `md`.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" size="xl" :total="100" />
</template>
```

### Отключение

Пропс `disabled` отключает элементы управления пагинацией.

```vue
<script setup lang="ts">
const page = ref(5)
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" disabled />
</template>
```

## Примеры

### Со ссылками

Пропс `to` превращает кнопки в ссылки. Передайте функцию, которая принимает номер страницы и возвращает маршрут.

```vue [PaginationLinksExample.vue]
<script setup lang="ts">
const page = ref(5)

function to(page: number) {
  return {
    query: {
      page
    },
    hash: '#with-links'
  }
}
</script>

<template>
  <B24Pagination v-model:page="page" :total="100" :to="to" :sibling-count="1" show-edges />
</template>
```

> [!NOTE]
> В этом примере к адресу добавлен хеш `#with-links`, чтобы страница не прокручивалась вверх.

## API

### Пропсы

```ts
/**
 * Props for the Pagination component
 */
interface PaginationProps {
  /**
   * The element or component this component should render as.
   * @default 'div'
   */
  as?: any;
  /**
   * The icon to use for the first page control.
   * @default icons.chevronDoubleLeft
   */
  firstIcon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  /**
   * The icon to use for the previous page control.
   * @default icons.chevronLeft
   */
  prevIcon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  /**
   * The icon to use for the next page control.
   * @default icons.chevronRight
   */
  nextIcon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  /**
   * The icon to use for the last page control.
   * @default icons.chevronDoubleRight
   */
  lastIcon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  /**
   * The icon to use for the ellipsis control.
   * @default icons.ellipsis
   */
  ellipsisIcon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  /**
   * The color of the pagination controls.
   * @default 'air-secondary-no-accent'
   */
  color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-copilot" | "air-secondary" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-secondary-no-accent" | "air-tertiary" | "air-tertiary-accent" | "air-tertiary-no-accent" | "air-selection" | "air-boost" | "link";
  /**
   * The color of the active pagination control.
   * @default 'air-primary'
   */
  activeColor?: "default" | "air-secondary-no-accent" | "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-copilot" | "air-secondary" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-tertiary" | "air-tertiary-accent" | "air-tertiary-no-accent" | "air-selection" | "air-boost" | "danger" | "success" | "warning" | "primary" | "secondary" | "collab" | "ai" | "link" | undefined;
  /**
   * Whether to show the first, previous, next, and last controls.
   * @default true
   */
  showControls?: boolean | undefined;
  size?: "xs" | "md" | "xss" | "sm" | "lg" | "xl" | undefined;
  /**
   * A function to render page controls as links.
   */
  to?: (page: number): string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric | undefined | undefined;
  b24ui?: { root?: SlotClass; list?: SlotClass; ellipsis?: SlotClass; label?: SlotClass; first?: SlotClass; prev?: SlotClass; item?: SlotClass; next?: SlotClass; last?: SlotClass; } | undefined;
  /**
   * The value of the page that should be active when initially rendered.
   * 
   * Use when you do not need to control the value state.
   */
  defaultPage?: number | undefined;
  /**
   * When `true`, prevents the user from interacting with item
   */
  disabled?: boolean | undefined;
  /**
   * Number of items per page
   * @default 10
   */
  itemsPerPage?: number | undefined;
  /**
   * The controlled value of the current page. Can be binded as `v-model:page`.
   */
  page?: number | undefined;
  /**
   * When `true`, always show first page, last page, and ellipsis
   * @default false
   */
  showEdges?: boolean | undefined;
  /**
   * Number of sibling should be shown around the current page
   * @default 2
   */
  siblingCount?: number | undefined;
  /**
   * Number of items in your list
   * @default 0
   */
  total?: number | undefined;
}
```

### Слоты

```ts
/**
 * Slots for the Pagination component
 */
interface PaginationSlots {
  first(): any;
  prev(): any;
  next(): any;
  last(): any;
  ellipsis(): any;
  item(): any;
}
```

### События

```ts
/**
 * Emitted events for the Pagination component
 */
interface PaginationEmits {
  update:page: (payload: [value: number]) => void;
}
```

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    pagination: {
      slots: {
        root: '',
        list: 'flex items-center gap-1',
        ellipsis: 'pointer-events-none',
        label: 'text-center',
        first: '',
        prev: '',
        item: '',
        next: '',
        last: ''
      }
    }
  }
})
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
