TablePaginationAPI
React TablePagination 組件的 API 參考文檔。了解此導出模組的 props、CSS 和其他 API。
範例
匯入
import TablePagination from '@mui/material/TablePagination';
// or
import { TablePagination } from '@mui/material';
透過閱讀這份關於最小化套件大小的指南,了解差異。
一個基於 TableCell
的組件,用於放置在 TableFooter
內以進行分頁。
TableCell 組件的 Props 也可用。
名稱 | 類型 | 預設 | 描述 |
---|---|---|---|
count* | 整數 | - | 總行數。 |
onPageChange* | 函式 | - | 頁面變更時觸發的回呼。 簽名: function(event: React.MouseEvent
|
page* | 整數 | - | 目前頁面的從零開始的索引。 |
rowsPerPage* | 整數 | - | 每頁的行數。 |
ActionsComponent | 元素類型 | TablePaginationActions | 用於顯示動作的組件。可以是字串(用於 HTML 元素)或組件。 |
backIconButtonProps | 物件 | - | 應用於後退箭頭 |
classes | 物件 | - | 覆寫或擴展應用於組件的樣式。 詳情請參閱下方的 CSS 類別 API。 |
component | 元素類型 | - | 用於根節點的組件。可以是字串(用於 HTML 元素)或組件。 |
disabled | 布林值 | false | 如果為 |
getItemAriaLabel | 函式 | function defaultGetAriaLabel(type) { return `前往 ${type} 頁面`; } | 接受一個函式,該函式傳回一個字串值,為目前頁面提供使用者友善的名稱。這對於螢幕閱讀器使用者來說很重要。 簽名: function(type: string) => string
|
labelDisplayedRows | 函式 | function defaultLabelDisplayedRows({ from, to, count }) { return `${from}–${to} / ${count !== -1 ? count : `超過 ${to}`}`; } | 自訂顯示的行標籤。使用 |
labelRowsPerPage | 節點 | '每頁行數:' | 自訂每頁行數標籤。 |
nextIconButtonProps | 物件 | - | 應用於下一個箭頭 |
onRowsPerPageChange | 函式 | - | 每頁行數變更時觸發的回呼。 簽名: function(event: React.ChangeEvent
|
rowsPerPageOptions | Array<number | { label: string, value: number }> | [10, 25, 50, 100] | 自訂每頁行數選擇欄位的選項。如果少於兩個選項可用,則不會顯示選擇欄位。使用 -1 作為具有自訂標籤的值以顯示所有行。 |
SelectProps | 物件 | {} | 應用於每頁行數 |
showFirstButton | 布林值 | false | 如果為 |
showLastButton | 布林值 | false | 如果為 |
slotProps | { actions?: { firstButton?: object, firstButtonIcon?: object, lastButton?: object, lastButtonIcon?: object, nextButton?: object, nextButtonIcon?: object, previousButton?: object, previousButtonIcon?: object }, displayedRows?: func | object, menuItem?: func | object, root?: func | object, select?: object, selectLabel?: func | object, spacer?: func | object, toolbar?: func | object } | {} | 用於每個 slot 內部的 props。 |
slots | { actions?: { firstButton?: elementType, firstButtonIcon?: elementType, lastButton?: elementType, lastButtonIcon?: elementType, nextButton?: elementType, nextButtonIcon?: elementType, previousButton?: elementType, previousButtonIcon?: elementType }, displayedRows?: elementType, menuItem?: elementType, root?: elementType, select?: elementType, selectLabel?: elementType, spacer?: elementType, toolbar?: elementType } | {} | 用於每個 slot 內部的組件。 |
sx | Array<func | object | bool> | func | object | - | 允許定義系統覆寫以及其他 CSS 樣式的系統 prop。 詳情請參閱 |
ref
會轉發到根元素。繼承
雖然上面未明確記錄,但 TableCell 組件的 props 也可在 TablePagination 中使用。您可以利用這一點來 鎖定巢狀組件。
主題預設 props
您可以使用 MuiTablePagination
來變更此組件的預設 props 透過主題。
Slot 名稱 | 類別名稱 | 預設組件 | 描述 |
---|---|---|---|
root | .MuiTablePagination-root | TableCell | 呈現 root slot 的組件。請遵循本指南以了解有關此組件需求的更多資訊。 |
toolbar | .MuiTablePagination-toolbar | Toolbar | 呈現 toolbar slot 的組件。請遵循本指南以了解有關此組件需求的更多資訊。 |
spacer | .MuiTablePagination-spacer | 'div' | 呈現 spacer slot 的標籤。 |
selectLabel | .MuiTablePagination-selectLabel | 'p' | 呈現 selectLabel slot 的標籤。 |
select | .MuiTablePagination-select | Select | 呈現 select slot 的組件。請遵循本指南以了解有關此組件需求的更多資訊。 |
menuItem | .MuiTablePagination-menuItem | MenuItem | 呈現 menuItem slot 的組件。請遵循本指南以了解有關此組件需求的更多資訊。 |
displayedRows | .MuiTablePagination-displayedRows | 'p' | 呈現 displayedRows slot 的標籤。 |
actions | .MuiTablePagination-actions | 傳遞到 actions slot 的 slots。 |
這些類別名稱對於使用 CSS 設定樣式很有用。當觸發特定狀態時,它們會應用於組件的 slots。
類別名稱 | 規則名稱 | 描述 |
---|---|---|
.MuiTablePagination-input | 輸入 | 應用於 Select 組件 root 元素的樣式。 |
.MuiTablePagination-selectIcon | 選取圖示 | 應用於 Select 組件 icon 類別的樣式。 |
.MuiTablePagination-selectRoot | 選取 Root | 應用於 Select 組件 root 元素的樣式。 |
您可以使用以下其中一種自訂選項來覆寫組件的樣式
- 使用 全域類別名稱。
- 在自訂主題中,使用規則名稱作為組件的
styleOverrides
屬性的一部分。
原始碼
如果您在本頁中找不到資訊,請考慮查看 組件的實作以取得更多詳細資訊。