Skip to content

Table 表格

用于展示多条结构类似的数据,可对数据进行排序、筛选、对比或其他自定义操作。

基础用法

最简单的表格用法。

ID
Name
Age
Email
1Alice24alice@example.com
2Bob28bob@example.com
3Charlie32charlie@example.com
4David21david@example.com
Example

多选

添加 row-selection 属性以开启多选功能。

Selected Keys: []
ID
Name
Status
1AliceActive
2BobInactive
Example

排序

在列配置中设置 sortable: true 即可开启排序功能。

Current Sort: None
ID
Name
Age
Score
1Alice2485
2Bob2892
3Charlie2178
4David3295
5Eve2488
Example

高阶用法

包含分页、排序、加载状态、斑马纹、带边框、以及自定义列渲染的综合用例。

ID
Name
Age
Status
Action
1User 120Active
2User 221Inactive
3User 322Active
4User 423Inactive
5User 524Active
Total 15 items
Example

API

Table Props

属性名说明类型默认值
data显示的数据any[][]
columns表格列的配置描述BrTableColumn[][]
rowKey表格行 key 的取值,可以是字符串或一个函数string | ((row: any) => string | number)'id'
stripe是否为斑马纹 tablebooleanfalse
border是否带有纵向边框booleanfalse
hover是否开启 hover 高亮booleantrue
loading是否显示加载状态booleanfalse
loadingText加载状态的文本提示string'Loading...'
emptyText空数据时的文本提示string'No Data'
rowSelection是否显示多选列booleanfalse
maxHeighttable 的最大高度string | number-
stickyHeader是否固定表头booleanfalse
pagination分页配置,设为 false 隐藏BrTablePagination | falsefalse

Table Events

事件名说明回调参数
update:selection多选状态发生变化时触发(selectedRowKeys: (string|number)[], selectedRows: any[])
update:pagination分页状态发生变化时触发(pagination: BrTablePagination)
sort排序发生变化时触发(sort: BrTableSort)
row-click当某一行被点击时触发(row: any, index: number, event: MouseEvent)

Table Slots

插槽名说明参数
cell-[key]自定义列的内容渲染{ row, column, index }

Column 配置 (BrTableColumn)

属性名说明类型默认值
key列的唯一标识string-
title列标题string-
width对应列的宽度string | number-
minWidth对应列的最小宽度string | number-
maxWidth对应列的最大宽度string | number-
align对齐方式'left' | 'center' | 'right''left'
fixed列是否固定在左侧或者右侧'left' | 'right' | boolean-
sortable对应列是否可以排序,custom 为自定义排序boolean | 'custom'false
render自定义渲染函数(row: any, index: number) => any-