manualPagination
pageCount
rowCount
autoResetPageIndex
onPaginationChange
getPaginationRowModel
setPagination
resetPagination
setPageIndex
resetPageIndex
setPageSize
resetPageSize
getPageOptions
getCanPreviousPage
getCanNextPage
previousPage
nextPage
firstPage
lastPage
getPageCount
getPrePaginationRowModel
getPaginationRowModel
分页状态以如下结构存储在表格中:
export type PaginationState = {
pageIndex: number
pageSize: number
}
export type PaginationTableState = {
pagination: PaginationState
}
export type PaginationInitialTableState = {
pagination?: Partial<PaginationState>
}
export type PaginationState = {
pageIndex: number
pageSize: number
}
export type PaginationTableState = {
pagination: PaginationState
}
export type PaginationInitialTableState = {
pagination?: Partial<PaginationState>
}
manualPagination?: boolean
manualPagination?: boolean
启用手动分页。若设为 true,表格不会自动使用 getPaginationRowModel() 分页行数据,而是期望你在传入数据前手动完成分页。适用于服务端分页 (server-side pagination) 和聚合场景。
pageCount?: number
pageCount?: number
在手动控制分页时,如果已知总页数可传入此值。若页数未知可设为 -1。替代方案是提供 rowCount 值,表格会据此内部计算 pageCount。
rowCount?: number
rowCount?: number
在手动控制分页时,如果已知总行数可传入此值。pageCount 将根据 rowCount 和 pageSize 内部计算得出。
autoResetPageIndex?: boolean
autoResetPageIndex?: boolean
设为 true 时,当发生影响分页的状态变更(如 data 更新、筛选条件变化、分组变化等),分页将重置到第一页。
🧠 注意:若 manualPagination 为 true,此选项默认为 false
onPaginationChange?: OnChangeFn<PaginationState>
onPaginationChange?: OnChangeFn<PaginationState>
提供此函数后,分页状态变化时会调用该函数,此时需自行管理状态。可通过 tableOptions.state.pagination 将管理后的状态传回表格。
getPaginationRowModel?: (table: Table<TData>) => () => RowModel<TData>
getPaginationRowModel?: (table: Table<TData>) => () => RowModel<TData>
返回仅经过分页处理后的行模型 (row model)。
默认情况下分页列会自动重排到列列表开头。若需保留原顺序或移除分页列,可在此设置对应模式。
setPagination: (updater: Updater<PaginationState>) => void
setPagination: (updater: Updater<PaginationState>) => void
设置或更新 state.pagination 状态。
resetPagination: (defaultState?: boolean) => void
resetPagination: (defaultState?: boolean) => void
将分页状态重置为 initialState.pagination,传入 true 可强制重置为默认空状态 []。
setPageIndex: (updater: Updater<number>) => void
setPageIndex: (updater: Updater<number>) => void
使用指定函数或值更新当前页码 (page index)。
resetPageIndex: (defaultState?: boolean) => void
resetPageIndex: (defaultState?: boolean) => void
重置页码至初始状态。若 defaultState 为 true,无论初始状态如何都会重置为 0。
setPageSize: (updater: Updater<number>) => void
setPageSize: (updater: Updater<number>) => void
使用指定函数或值更新每页大小 (page size)。
resetPageSize: (defaultState?: boolean) => void
resetPageSize: (defaultState?: boolean) => void
重置每页大小至初始状态。若 defaultState 为 true,无论初始状态如何都会重置为 10。
getPageOptions: () => number[]
getPageOptions: () => number[]
返回基于当前每页大小的页码选项数组(从零开始索引)。
getCanPreviousPage: () => boolean
getCanPreviousPage: () => boolean
返回表格是否能跳转到上一页。
getCanNextPage: () => boolean
getCanNextPage: () => boolean
返回表格是否能跳转到下一页。
previousPage: () => void
previousPage: () => void
将当前页码减一(如果允许)。
nextPage: () => void
nextPage: () => void
将当前页码加一(如果允许)。
firstPage: () => void
firstPage: () => void
跳转到第一页(页码设为 0)。
lastPage: () => void
lastPage: () => void
跳转到最后一页。
getPageCount: () => number
getPageCount: () => number
返回总页数。如果是手动分页或控制分页状态,此值直接来自 options.pageCount 选项,否则会根据总行数和当前每页大小计算得出。
getPrePaginationRowModel: () => RowModel<TData>
getPrePaginationRowModel: () => RowModel<TData>
返回未应用分页前的原始行模型。
getPaginationRowModel: () => RowModel<TData>
getPaginationRowModel: () => RowModel<TData>
返回应用分页处理后的行模型。
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.