> For AI agents: the complete documentation index is available at https://rickyshin93.github.io/tao-ui/zh/llms.txt, the full documentation bundle is available at https://rickyshin93.github.io/tao-ui/zh/llms-full.txt.

# Pagination

导航`@rockshin/tao-ui`

[代码演示](#代码演示)[API](#api)

在较大数据集合的分页之间导航。

## 何时使用

列表或表格无法一次有效展示全部结果时使用 Pagination。

**推荐**

- 在数据变化时保持当前页有效。
- 需要时展示总数和每页数量。

**避免**

- 少量内容不需要分页。

## 代码演示


### 基础用法
```tsx preview
import { Pagination } from '@rockshin/tao-ui';
import { useState } from 'react';

function PaginationExample() {
  const [page, setPage] = useState(1);

  return (
    <Pagination
      total={95}
      current={page}
      pageSize={10}
      onChange={setPage}
      showTotal={(total, range) => range[0] + '-' + range[1] + ' of ' + total}
    />
  );
}

export default PaginationExample;
```

### 尺寸
```tsx preview
import { Pagination, Stack } from '@rockshin/tao-ui';

function PaginationSizes() {
  return (
    <Stack gap="md">
      <Pagination total={50} size="small" />
      <Pagination total={50} size="medium" />
      <Pagination total={50} size="large" />
    </Stack>
  );
}

export default PaginationSizes;
```

### 每页数量与总数
```tsx preview
import { Pagination } from '@rockshin/tao-ui';
import { useState } from 'react';

function PaginationPageSize() {
  const [page, setPage] = useState(1);
  const [pageSize, setPageSize] = useState(10);

  return (
    <Pagination
      total={200}
      current={page}
      pageSize={pageSize}
      showSizeChanger
      showTotal={(total, range) => range[0] + '-' + range[1] + ' of ' + total}
      onChange={(nextPage, nextPageSize) => {
        setPage(nextPage);
        setPageSize(nextPageSize);
      }}
    />
  );
}

export default PaginationPageSize;
```

### 显示数据总量
`showTotal` 可以展示当前记录区间与总数量。
```tsx preview
import { Pagination } from '@rockshin/tao-ui';

import { useState } from 'react';

export default function PaginationWithTotal() {
  function Demo() {
    const [page, setPage] = useState(1);
    return (
      <Pagination
        total={95}
        current={page}
        pageSize={10}
        onChange={(p) => setPage(p)}
        showTotal={(t, [s, e]) => `${s}-${e} of ${t}`}
      />
    );
  }
  return <Demo />;
}
```

### 切换每页条数
将页码和每页数量一起维护，数据请求应使用变更后的两个值。
```tsx preview
import { Pagination } from '@rockshin/tao-ui';

import { useState } from 'react';

export default function PaginationSizeChanger() {
  function Demo() {
    const [page, setPage] = useState(1);
    const [ps, setPs] = useState(10);
    return (
      <Pagination
        total={200}
        current={page}
        pageSize={ps}
        onChange={(p, s) => {
          setPage(p);
          setPs(s);
        }}
        showSizeChanger
      />
    );
  }
  return <Demo />;
}
```

### 分页尺寸
尺寸影响分页按钮的密度，可与所在列表或表格匹配。
```tsx preview
import { Pagination } from '@rockshin/tao-ui';

export default function PaginationSizes() {
  return (
    <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
      <Pagination total={50} size="small" />
      <Pagination total={50} size="medium" />
      <Pagination total={50} size="large" />
    </div>
  );
}
```

## API


### [#](#pagination)Pagination



| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| disabled | 是否禁用 | `boolean | undefined` | `-` |
| className | 节点类名 | `string | undefined` | `-` |

