跳转到内容

Pagination 分页

使用可自定义的控件浏览数据页面。

import { Pagination } from 'asterui'

基础分页

带有页码的简单分页。

import { Pagination } from 'asterui'
import { useState } from 'react'

function App() {
  const [current, setCurrent] = useState(1);
  
  return (
      <Pagination
        current={current}
        total={85}
        onChange={(page) => setCurrent(page)}
      />
    )
}

export default App

带尺寸更改器

允许用户更改每页大小。

import { Pagination } from 'asterui'
import { useState } from 'react'

function App() {
  const [current, setCurrent] = useState(1);
  const [pageSize, setPageSize] = useState(10);
  
  return (
      <Pagination
        current={current}
        total={500}
        pageSize={pageSize}
        showSizeChanger
        onChange={(page, size) => {
          setCurrent(page);
          setPageSize(size);
        }}
      />
    )
}

export default App

显示总数

显示项目总数。

Total 250 items
import { Pagination } from 'asterui'

function App() {
  return (
      <Pagination total={250} showTotal />
    )
}

export default App

自定义总数

自定义总数的渲染。

Showing 1-10 of 250 items
import { Pagination } from 'asterui'

function App() {
  return (
      <Pagination
        total={250}
        showTotal={(total, range) => `Showing ${range[0]}-${range[1]} of ${total} items`}
      />
    )
}

export default App

快速跳转

允许用户跳转到特定页面。

Go to
import { Pagination } from 'asterui'

function App() {
  return (
      <Pagination total={500} showQuickJumper />
    )
}

export default App

所有功能

启用所有功能的分页。

1-10 of 500
Go to
import { Pagination } from 'asterui'
import { useState } from 'react'

function App() {
  const [current, setCurrent] = useState(1);
  
  return (
      <Pagination
        current={current}
        total={500}
        showSizeChanger
        showQuickJumper
        showTotal={(total, range) => `${range[0]}-${range[1]} of ${total}`}
        onChange={(page) => setCurrent(page)}
      />
    )
}

export default App

简单模式

仅带有上一页/下一页控件的最小分页。

1 / 10
import { Pagination } from 'asterui'

function App() {
  return (
      <Pagination total={100} simple />
    )
}

export default App

尺寸

分页控件的不同尺寸。

Extra Small
Small
Medium (default)
Large
import { Pagination } from 'asterui'

function App() {
  return (
      <div className="space-y-4">
        <div>
          <div className="text-sm text-base-content/60 mb-2">Extra Small</div>
          <Pagination total={100} size="xs" />
        </div>
        <div>
          <div className="text-sm text-base-content/60 mb-2">Small</div>
          <Pagination total={100} size="sm" />
        </div>
        <div>
          <div className="text-sm text-base-content/60 mb-2">Medium (default)</div>
          <Pagination total={100} size="md" />
        </div>
        <div>
          <div className="text-sm text-base-content/60 mb-2">Large</div>
          <Pagination total={100} size="lg" />
        </div>
      </div>
    )
}

export default App

禁用

分页的禁用状态。

import { Pagination } from 'asterui'

function App() {
  return (
      <Pagination total={100} disabled />
    )
}

export default App
属性描述类型默认值
current当前页码(受控)number-
defaultCurrent默认初始页码number1
total项目总数number-
pageSize每页项目数(受控)number-
defaultPageSize默认每页项目数number10
pageSizeOptions页面大小选择器的选项number[][10, 20, 50, 100]
onChange页面或 pageSize 更改时的回调(page: number, pageSize: number) => void-
onShowSizeChangepageSize 更改时的回调(current: number, size: number) => void-
showSizeChanger显示页面大小选择器booleanfalse
showQuickJumper显示快速跳转到页面的输入booleanfalse
showTotal显示总数或自定义渲染函数boolean | ((total: number, range: [number, number]) => ReactNode)false
simple简单模式,带有最少的控件booleanfalse
size分页按钮的尺寸'xs' | 'sm' | 'md' | 'lg''md'
disabled禁用所有分页控件booleanfalse
className额外的 CSS 类string-
  • 使用带有 aria-label="Pagination"nav 元素
  • 当前页面用 aria-current="page" 标记
  • 禁用的按钮具有正确的 aria-disabled 状态
  • 快速跳转输入具有可访问的标签