Skip to content

Table 表格组件

Table 组件提供了高级表格展示功能,支持分页、排序、搜索等特性。
自动请求,额外参数,flex布局table高度自适应,操作列的封装,toolbar 和 title显示。
插槽支持自定义渲染,自定义样式,自定义操作列,自定义分页,自定义搜索,自定义排序。
以及行的拖拽排序和 table 的纵向虚拟滚动等功能。

基本用法

下面是一个基本示例: alt text

表单搜索 alt textalt text

一行代码开启表头搜索(headerSearchComponent 设为 Input 或者 Checkbox)

js
{
    title: '价格',
    align: 'center',
    // hideInSearch: true,
    headerSearchComponent: 'Input',
    dataIndex: 'price',
    formItemProps: {
      component: 'Select',
    },
    customRender: ({ record }) => `${record.price}元`,
  },

alt text

loading

API

Props

参数说明类型默认值
AntV 的左右 table 参数都支持参考链接--
columns表格列配置Array<TableColumn>[]
search是否显示搜索表单Booleantrue
formProps表单属性配置FormProps{}
dataRequest表格数据请求函数Function
showIndex是否显示索引号Booleanfalse
indexColumnProps索引列属性配置TableColumn{}
showToolBar是否显示表格工具栏Booleantrue
showTableSetting是否显示表格设置Booleantrue
headerTitle表格标题String-
titleTooltip表格标题提示信息String-
showRefresh是否显示刷新按钮Booleanfalse
isSelect/ 是否支持选中Booleanfalse
isMultipleSelect是否支持多选Booleanfalse
showSearchBorder是否显示表格搜索下的 borderBooleantrue
isExtraParamsChangeQuery额外参数改变是否立刻触发查询Booleantrue
extraParams表格额外参数Object{}
maxActionCount操作列最大按钮数, 超出用 ... 显示Number4
pageSizeChangeToFirst切换 pageSize 是否回到第一页Booleanfalse
virtualScroll是否开启纵向虚拟滚动Booleanfalse
dragSort是否开启拖拽排序功能Booleanfalse

TableColumn 参数

参数说明类型默认值
dataIndex和 AntV 一样--
searchField指定搜索的字段string-
hideInSearch在查询表单中不展示此项boolean-
hideInTable在 Table 中不展示此列boolean-
formItemProps传递给搜索表单 Form.Item 的配置,可以配置 rulesPartial<FormSchema<T>>-
headerSearchComponent表头搜索组件string-
headerSearchComponentProps表头搜索组件属性Recordable-
actions操作列,一般用于对表格某一行数据进行操作(params: CustomRenderParams<T>, action: TableActionType) => ActionItem[]-
childrenchildrenTableColumn<T>[]-

Methods

方法说明参数返回值
fetchData拉取表格数据params, reset(table change时间的参数一致)Promise
refresh刷新表格数据voidvoid
getQueryFormRef获取查询表单实例voidFormInstance
reRenderTable重新渲染表格voidvoid
getTableData获取表格数据voidT[]
updateTableData更新表格数据data: T[]void
addColumn添加 column, 在 dataIndex 之前 columns 添加, 如果没有 dataIndex 则添加到最后column: TableColumn | TableColumn[], dataIndex: stringvoid
removeColumn移除 columndataIndex: string | string[]void
updateColumn更新 columncolumn: TableColumn | TableColumn[]void
replaceColumn替换 columncolumn: TableColumn | TableColumn[]void

插槽

支持自定义渲染的插槽,允许用户根据需求自定义表格的某些部分。

名称说明
Form的slotForm 组件支持的插槽
headerTitle表格标题
toolbar表格工具栏