跳至主要内容

表格

輸入參數即可快速建立表格資料。預設設定包括分頁。

import AcroolTable from '@acrool/react-table';

const data: IPaginateData[] = [
{id: 1, name: 'Jack Wu', role: 'Admin', amount: 230},
{id: 2, name: 'Imagine Chiu', role: 'Guest', amount: 120},
{id: 3, name: 'Jason Dinwiddie', role: 'Manage', amount: 200},
{id: 4, name: 'Gloria Lu', role: 'Guest', amount: 300},
];

<AcroolTable
title={{
name: {text: 'Name', col: 'auto'},
role: {text: 'Role', col: '120px'},
}}
data={data.map(row => {
return {
id: row.id,
field: {
name: row.name,
role: row.role,
},
};
})}
/>
Title
Text
Image Chiuthis is a frontend coder
Gary Chienthis is a backend coder
Loading...
Show 1 - 0 itemTotal 0 item / 1 Page

Props

Props NameTypeRequiredDefaultDescription
styleCSS.Properties
classNamestring
isDarkboolean暗黑主題
isFetchingboolean是否顯示讀取中遮罩
titleTTableTitle<K>表頭列設定
dataITableBody<K,I>[]資料列設定
footerTFooter<K>頁尾資訊列設定
headerLineHeightTLineHeight表頭列高度設定
bodyLineHeightTLineHeight內容列高度設定
footerLineHeightTLineHeight頁尾列高度設定
cellLineHeightTLineHeightcell模式高度設定
gapstring5px間距設定
paginateInfoIPaginateInfo{totalItems: 0,totalPages: 1}目前分頁資訊
paginateMetaIPaginateMeta指定分頁設定
nextTextReactNode下一頁按鈕文字設定
prevTextReactNode上一頁按鈕文字設定
isVisibleHeaderbooleantrue是否顯示表頭
isVisiblePaginatebooleantrue是否顯示分頁
isEnableChangePageScrollTopbooleantrue切換頁時,是否移動到最上方
tableCellMediaSizenumberCell顯示模式的最大尺寸設定
onChangePageTOnChangePage當換頁時呼叫方法
pageLimitOptionsnumber[][8, 40, 72, 150]一頁顯示幾筆的下拉選單
orderByTypeIOrderByType排序類型對應字串
renderNoData() => JSX.Element|string渲染無資料時顯示方式
renderPageButton(args: IPageButtonArgs) => ReactNode渲染分頁按鈕
renderFetching() => JSX.Element|string'Loading...'渲染讀取中樣式內容
type TLineHeight = `${number}${TSizeUnit}`|'auto'

TTableTitle

type TTableTitle<K extends string> = {
[P in K]: ITitleField;
}

ITitleField

Props NameTypeRequiredDescription
classNamestring
colTTitleCol欄位寬度
textstring|number | ReactNode顯示內容
titleAlign'left'|'center' |'right'標題水平對期方式
isEnableSortbooldan是否啟用排序功能
isStickybooldan是否欄位沾黏
isHiddenbooldan是否隱藏欄位
type TSizeUnit = 'px' | '%' | 'em' | 'fr' | 'rem';
type TTitleCol = true|'auto'|number|`${number}${TSizeUnit}`|'min-content'|'max-content'|`minmax('${number}${TSizeUnit}', '${number}${TSizeUnit}')`;

IConfig

Props NameTypeRequiredDescription
colSpannumber
dataAlign'left'|'center' |'right'垂直排序
dataVertical'top'|'center' |'bottom'水平排序

IOrderByType

Props NameTypeRequiredDefaultDescription
ascstring對應的字串按升序排列
descstring將對應的字串依降序冪排列

ITableBody

Props NameTypeRequiredDefaultDescription
idI識別碼 ID (Array key)
classNamestring
detailJSX.Element | TBodyDataDetail<K>[]額外內容明細
disabledboolean是否禁用
onClickRow(collapse: () => void) => void點擊列時呼叫的方法
fieldTBodyDataField<K>欄位設定
type TBodyDataDetail<K extends TBodyDataFieldKey> = {
[P in K]?: { value: TFieldValue } & IConfig;
}
type TFieldFunc = (args: TFieldFuncArgs) => TFieldValue;

type TBodyDataFieldKey = string;
type TFieldValue = string | number | boolean | JSX.Element;

type TBodyDataField<K extends TBodyDataFieldKey> = {
[P in K]?: TFieldValue | TFieldFunc | { value: TFieldValue } & IConfig;
}

IOrder

Props NameTypeRequiredDefaultDescription
orderFieldnumber
orderBynumber