Skip to content

Table

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

基础用法

显示工具栏

多选

多级表头

自定义列模板

自定义表头

展开行

树形数据与懒加载

Table 属性

属性名说明类型默认值
rowKey行数据的 Key,用来优化 Table 的渲染string
indexColumn索引序列号boolean |{width: number, label: string}true
toolbar是否显示工具栏booleantrue
columns列表字段<ITableColumn[]>(array)
pagination分页boolean/ITablePagination(object)ITablePagination
dataSource数据源array
border是否带有纵向边框booleantrue
loading加载占位符booleanfalse
defaultSort默认的排序列的 prop 和顺序<Sort>(object)false
cacheKey缓存的 keystringundefined
showColumnsSetting是否显示列设置booleantrue
columnSettingCache<ITableColumnSetting[]>(array)
highlightCurrentRow是否要高亮当前行booleanfalse
rowSelection表格行是否可选择<ITableRowSelection>(object)
maxHeightTable 的最大高度。 合法的值为数字或者单位为 px 的高度。string/number
defaultExpandAll是否默认展开所有行,当 Table 包含展开行存在或者为树形表格时有效booleanfalse
lazy是否懒加载子节点数据booleanfalse
treeProps渲染嵌套数据的配置选项object
load加载子节点数据的函数,lazy 为 true 时生效function(row, treeNode, resolve)
showSummary是否在表尾显示合计行booleanfalse
summaryMethod自定义的合计计算方法function(SummaryMethod)false
tableLayout设置表格单元、行和列的布局方式stringfixed
tableLayout设置表格单元、行和列的布局方式stringfixed
cellClassName单元格的 className 的回调方法string
cellStyle单元格的 style 的回调方法string
rowClassName行的 className 的回调方法string
rowStyle行的 style 的回调方法string
spanMethod合并行或列的计算方法function(row, column, rowIndex, columnIndex)
scrollbarAlwaysOn总是显示滚动条booleantrue
customFilter是否显示自定义筛选配置booleanfalse
stripe是否为斑马纹 tablebooleanfalse
emptyText空数据时显示的文本内容stringNo Data

Table 事件

事件名说明参数
row-click当某一行被点击时会触发该事件row
cell-click当某个单元格被点击时会触发该事件property, value
on-pagination-current-changecurrent-page 改变时触发page
on-pagination-size-changepage-size 改变时触发size
sort-change当表格的排序条件发生变化的时候会触发该事件{prop, order}
refresh刷新列表
current-change当表格的当前行发生变化的时候会触发该事件,如果要高亮当前行,请打开表格的 highlight-current-row 属性currentRow,oldCurrentRow
column-setting-change保存列设置ITableColumnSetting(array)
expand-change当某一行展开或者关闭的时候会触发该事件currentRow, expanded

Table 插槽

插槽名说明
table-header表格头部
table-toolbar-left工具栏左侧
table-toolbar-right工具栏右侧
column-{prop}自定义列插槽,prop 为 column prop 字段
column-header-{prop}自定义表头插槽,prop 为 column prop 字段

Table Column 属性

属性名说明类型可选值默认值
type对应列的类型
width对应列的宽度string/number
minWidth对应列的最小宽度string/number
fixed列是否固定在左侧或者右侧。 true 表示固定在左侧string/booleantrue / left / right
sortable对应列是否可以排序boolean
sortBy指定数据按照哪个属性进行排序(row: any, index: number) => string/string/object
label显示的标题string
className列的 classNamestring
prop字段名称 对应列内容的字段名string
slot自定义列,插槽boolean
headerSlot自定义表头,插槽boolean
format用来格式化内容string
ellipsisellipsisboolean
align对齐方式stringleft / center / right
mapobject
filters数据过滤的选项,数组格式,每个元素都需要有 text 和 value 属性Array<{text: string, value: string}>
filterMethod过滤方法function(value,row,column)
formatter用来格式化内容function(row,column,cellValue,index)
buttonsArray<{label,actionType,visible,onClick,popconfirm}>
onClick点击事件function(row)
children子对象Array<>