分页
分页器用于分隔长列表,每次只加载一个页面。
何时使用
- 当加载/渲染所有数据将花费很多时间时;
- 可切换页码浏览数据。
代码演示
-
基本 ·
basic -
方向 ·
align -
更多 ·
more -
改变 ·
changer -
跳转 ·
jump -
尺寸 ·
mini -
简洁 ·
simple -
受控 ·
controlled -
总数 ·
total -
全部展示 ·
all -
上一步和下一步 ·
itemRender -
定制组件 ·
components -
自定义语义结构的样式和类 ·
style-class
API
通用属性参考:通用属性
<Pagination onChange={onChange} total={50} />
| 参数 | 说明 | 类型 | 默认值 | 版本 | 全局配置 |
|---|---|---|---|---|---|
| align | 对齐方式 | start | center | end | - | 5.19.0 | × |
| classNames | 自定义组件内部各语义化结构的类名。支持对象或函数 | Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string> | - | 6.0.0 | |
| components | 自定义内部组件 | { sizeChanger?: React.ComponentType } | - | 6.6.0 | × |
| current | 当前页数 | number | - | × | |
| defaultCurrent | 默认的当前页数 | number | 1 | × | |
| defaultPageSize | 默认的每页条数 | number | 10 | × | |
| disabled | 禁用分页 | boolean | - | × | |
| hideOnSinglePage | 只有一页时是否隐藏分页器 | boolean | false | × | |
| itemRender | 用于自定义页码的结构,可用于优化 SEO | (page, type: 'page' | 'prev' | 'next', originalElement) => React.ReactNode | - | × | |
| pageSize | 每页条数 | number | - | × | |
| pageSizeOptions | 指定每页可以显示多少条 | number[] | [10, 20, 50, 100] | × | |
| responsive | 当 size 未指定时,根据屏幕宽度自动调整尺寸 | boolean | - | × | |
| showLessItems | 是否显示较少页面内容 | boolean | false | × | |
| showQuickJumper | 是否可以快速跳转至某页 | boolean | { goButton: ReactNode } | false | × | |
| showSizeChanger | 是否展示 pageSize 切换器 | boolean | SelectProps | - | SelectProps: 5.21.0 | 4.21.0,SelectProps: 5.21.0 |
| showTitle | 是否显示原生 tooltip 页码提示 | boolean | true | × | |
| showTotal | 用于显示数据总量和当前数据顺序 | function(total, range) | - | × | |
| simple | 当添加该属性时,显示为简单分页 | boolean | { readOnly?: boolean } | - | × | |
| size | 组件尺寸 | large | medium | small | medium | × | |
| styles | 自定义组件内部各语义化结构的内联样式。支持对象或函数 | Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties> | - | 6.0.0 | |
| total | 数据总数 | number | 0 | × | |
| totalBoundaryShowSizeChanger | 当 total 大于该值时,showSizeChanger 默认为 true | number | 50 | 6.2.0 | |
| onChange | 页码或 pageSize 改变的回调,参数是改变后的页码及每页条数 | function(page, pageSize) | - | × | |
| onShowSizeChange | pageSize 变化的回调 | function(current, size) | - | × |
Semantic DOM
| 语义节点 | 原生说明 | 版本 |
|---|---|---|
root | 根元素,设置flex布局、对齐方式、换行和列表样式 | 6.0.0 |
item | 页码元素,设置尺寸、内边距、边框、背景色、悬停态和激活态样式 | 6.0.0 |
语义说明来源: vendor/components/pagination/demo/_semantic.tsx
主题变量(Design Token)
类型、继承关系和原生令牌声明保持固定源码原文;默认值由原生主题计算,并可能受 ConfigProvider 覆盖。本表不伪造静态默认值。
| 令牌 | 类型 | 原生说明 |
|---|---|---|
itemBg | string | 页码选项背景色 |
itemSize | number | 页码尺寸 |
itemSizeSM | number | 小号页码尺寸 |
itemSizeLG | number | 大号页码尺寸 |
itemActiveBg | string | 页码激活态背景色 |
itemActiveColor | string | 页码激活态文字颜色 |
itemActiveColorHover | string | 页码激活态文字颜色悬停态 |
itemLinkBg | string | 页码链接背景色 |
itemActiveBgDisabled | string | 页码激活态禁用状态背景色 |
itemActiveColorDisabled | string | 页码激活态禁用状态文字颜色 |
itemInputBg | string | 输入框背景色 |
miniOptionsSizeChangerTop | number | 每页展示数量选择器 top |
声明来源: vendor/components/pagination/style/index.ts
import { unit } from '@ant-design/cssinjs';
import type { CSSObject } from '@ant-design/cssinjs';
import {
genBasicInputStyle,
genInputLargeStyle,
genInputSmallStyle,
initComponentToken,
initInputToken,
} from '../../input/style';
import type { SharedComponentToken, SharedInputToken } from '../../input/style/token';
import { genBaseOutlinedStyle, genDisabledStyle } from '../../input/style/variants';
import { genFocusOutline, genFocusStyle, resetComponent } from '../../style';
import type { FullToken, GenerateStyle, GenStyleFn, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
import { genCssVar } from '../../theme/util/genStyleUtils';
export interface ComponentToken {
/**
* @desc 页码选项背景色
* @descEN Background color of Pagination item
*/
itemBg: string;
/**
* @desc 页码尺寸
* @descEN Size of Pagination item
*/
itemSize: number;
/**
* @desc 小号页码尺寸
* @descEN Size of small Pagination item
*/
itemSizeSM: number;
/**
* @desc 大号页码尺寸
* @descEN Size of large Pagination item
*/
itemSizeLG: number;
/**
* @desc 页码激活态背景色
* @descEN Background color of active Pagination item
*/
itemActiveBg: string;
/**
* @desc 页码激活态文字颜色
* @descEN Text color of active Pagination item
*/
itemActiveColor: string;
/**
* @desc 页码激活态文字颜色悬停态
* @descEN Text color of active Pagination item hover
*/
itemActiveColorHover: string;
/**
* @desc 页码链接背景色
* @descEN Background color of Pagination item link
*/
itemLinkBg: string;
/**
* @desc 页码激活态禁用状态背景色
* @descEN Background color of disabled active Pagination item
*/
itemActiveBgDisabled: string;
/**
* @desc 页码激活态禁用状态文字颜色
* @descEN Text color of disabled active Pagination item
*/
itemActiveColorDisabled: string;
/**
* @desc 输入框背景色
* @descEN Background color of input
*/
itemInputBg: string;
/**
* @desc 每页展示数量选择器 top
* @descEN Top of Pagination size changer
*/
miniOptionsSizeChangerTop: number;
}
/**
* @desc Pagination 组件的 Token
* @descEN Token for Pagination component
*/
export interface PaginationToken
extends FullToken<'Pagination'>, SharedComponentToken, SharedInputToken {
/**
* @desc 输入框轮廓偏移量
* @descEN Outline offset of input
*/
inputOutlineOffset: number;
/**
* @desc 快速跳转输入框宽度
* @descEN Width of quick jumper input
*/
quickJumperInputWidth: number | string;
/**
* @desc 迷你选项横向外边距
* @descEN Horizontal margin of mini options
*/
paginationMiniOptionsMarginInlineStart: number | string;
/**
* @desc 迷你快速跳转输入框宽度
* @descEN Width of mini quick jumper input
*/
paginationMiniQuickJumperInputWidth: number | string;
/**
* @desc 页码横向内边距
* @descEN Horizontal padding of Pagination item
*/
paginationItemPaddingInline: number | string;
/**
* @desc 省略号字母间距
* @descEN Letter spacing of ellipsis
* @deprecated Ellipsis is now an SVG icon, this token is no longer used.
*/
paginationEllipsisLetterSpacing: number | string;
/**
* @desc 省略号文本缩进
* @descEN Text indent of ellipsis
* @deprecated Ellipsis is now an SVG icon, this token is no longer used.
*/
paginationEllipsisTextIndent: string;
/**
* @desc 斜杠横向外边距
* @descEN Horizontal margin of slash
*/
paginationSlashMarginInlineStart: number;
/**
* @desc 斜杠横向外边距
* @descEN Horizontal margin of slash
*/
paginationSlashMarginInlineEnd: number;
}
原生通用属性
Tips: 以下通用属性适用于 antd 大部分组件,不支持的组件会单独说明。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| style | 自定义样式 | CSSProperties | - |
| className | 自定义类名 | string | - |
| rootClassName | 添加在组件最外层的 className | string | - |
| autoFocus | 自动获取焦点,仅对表单类、链接、交互容器等可聚焦元素生效 | boolean | false |
安装并复现示例
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
使用 ConfigProvider 和原生 App,并单独配置 dayjs 语言。每个示例在查看代码中列出完整源码文件和额外固定依赖。示例名称用于选择演示,不是组件通用属性。主题、语言与 SSR 初始化见资源安装指南。
原生类型参考
源码查看器包含未修改的原生实现和以下声明文件,继承类型仍位于原生包中。代码中的英文注释保留为源码参考。
vendor/components/pagination/Pagination.tsxvendor/components/pagination/style/index.ts
来源与许可
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
保留原生中英文正文与可执行示例;官网专用的嵌入章节和令牌表格在本地展开。Ant Design 使用 MIT 许可,另列依赖的许可证也需保留。上传预览禁止向外发起请求,不提供后端服务。