1.0.8 • Published 1 year ago

vue-table-solution v1.0.8

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

vue-table-solution

vue-table-solution 是 基于 Vue 3 + Vite 4 + Ant Design Vue 3 + Surely Vue Table 实现的“高端”组件。致力于解决大数据渲染、图表集成等复杂高频问题。 使用该组件可以流畅滚动 10 万行、10 万列的数据,你不必担心页面卡顿造成用户投诉,进而影响业务进展。

vue-table-solution 默认使用虚拟滚动提升渲染速度,树形数据、展开内容、嵌套子表格、行列合并、自动行高、横向、纵向、吸顶、固定头、固定列等等一切都支持虚拟滚动。

功能点

以下是当前已经支持和正在开发中的功能:

功能状态
边框定制紧凑自定义单元格自定义行样式斑马纹单列排序多列排序服务端排序单选多选反选全选筛选自定义筛选列宽拖动固定头固定列表头吸顶分页自定义分页页头页尾合计表头合并表头分组行合并列合并增删改查折叠数据树形数据嵌套子表格虚拟行滚动虚拟列滚动加载中空数据编辑单元格编辑行自动行高国际化动画拖拽排序暗黑模式右键功能集
图表文件导入复制导入打印导出 CSV导出 EXCEL🚧

API

Table

参数说明类型默认值版本
animateRows是否开启动画booleantrue
autoHeaderHeight是否自动表头高度,开启后会全量加载表头部分,有一定的性能损耗booleanfalse2.3
bordered是否展示外边框和列边框booleanfalse
columns表格列的配置描述,具体项见下表array-
childrenColumnName指定树形结构的列名stringchildren
dataSource数据数组object[]
defaultExpandAllRows初始时,是否展开所有行booleanfalse
defaultExpandedRowKeys默认展开的行string[]-
expandedRowKeys展开的行,控制属性string[]-
expandedRowRender额外的展开行Function({record, index, indent, expanded}):VNode | v-slot:expandedRowRender="{record, index, indent, expanded}"-
expandFixed控制展开图标是否固定,可选 true left rightboolean | stringfalse
expandIcon自定义展开图标Function(props):VNode | v-slot:expandIcon="props"-
expandRowByClick通过点击行来展开子行booleanfalse
expandIconColumnIndex自定义展开按钮的列顺序,-1 时不展示number-
footer表格尾部Function(currentPageData)|v-slot:footer="currentPageData"
getPopupContainer设置表格内各类浮层的渲染节点,如筛选菜单(triggerNode) => HTMLElement() => TableHtmlElement
loading页面是否加载中boolean|objectfalse
locale默认文案设置,目前包括排序、过滤、空数据文案objectfilterConfirm: 确定 filterReset: 重置 emptyText: 暂无数据
pagination分页器,参考配置项,设为 false 时不展示和进行分页object
rowClassName表格行的类名Function(record, index):string-
rowKey表格行 key 的取值,可以是字符串或一个函数string|Function(record):string'key'
rowSelection列表项是否可选择,配置项objectnull
scroll表格是否可滚动,也可以指定滚动区域的宽、高,配置项object-
showHeader是否显示表头booleantrue
showSorterTooltip表头是否显示下一次排序的 tooltip 提示。当参数类型为对象时,将被设置为 Tooltip 的属性boolean | Tooltip propstrue
size表格大小default | middle | smalldefault
sortDirections支持的排序方式,取值为 ascend descendArray[ascend, descend]
sticky设置粘性头部和滚动条boolean | {offsetHeader?: number, offsetScroll?: number, getContainer?: () => HTMLElement, topSummary?: boolean }-topSummary 2.4.7
title表格标题Function(currentPageData)|v-slot:title="currentPageData"
indentSize展示树形数据时,每层缩进的宽度,以 px 为单位number15
rowExpandable设置是否允许行展开(record) => boolean-
customRow设置行属性Function(record, index)-
headerCell个性化头部单元格v-slot:headerCell="{title, column}"-
bodyCell个性化单元格v-slot:bodyCell="{text, record, index, column, key}"-
customCell设置单元格属性, column 如配置了 customCell, 优先使用 column.customCellFunction(obj: {record: any; rowIndex: number; column: ColumnType})-
customFilterDropdown自定义筛选菜单,需要配合 column.customFilterDropdown 使用v-slot:customFilterDropdown="FilterDropdownProps"-
customFilterIcon自定义筛选图标v-slot:customFilterIcon="{filtered, column}"-
emptyText自定义空数据时的显示内容v-slot:emptyText-
summary总结栏v-slot:summary-
summaryFixed固定总结栏boolean | 'top'(2.4.6) | 'bottom'-
rowDragGhost自定义拖拽行时的提示内容v-slot:rowDragGhost="arg: RowDragGhostArg"-2.1.0
columnDrag列表头是否允许拖拽, 详见boolean-2.1.1
columnDragGhost自定义拖拽列时的提示内容v-slot:columnDragGhost="arg: ColumnDragGhostArg"-2.1.1
rowHoverDelay表格行 hover 延时,用于性能优化number502.2.0
xVirtual横向是否虚拟滚动boolean-2.4.1
ignoreCellKey忽略单元格唯一 key,进一步提升自定义组件复用,bodyCell 插槽新增 key 参数,可根据组件情况自行选用。booleanfalse2.4.4
showHeaderScrollbar显示表头滚动条booleanfalse2.4.4
rowHeight配置行高,组件内部默认会根据 size 自动调整高度,如果需要自定义高度可使用该属性number | ((p: Record<any, any>, isExpandRow: boolean, baseHeight: number) => numberundefined-
  • expandFixed
    • 当设置为 true 或 leftexpandIconColumnIndex 未设置或为 0 时,开启固定
    • 当设置为 true 或 rightexpandIconColumnIndex 设置为表格列数时,开启固定

事件

事件名称说明回调参数版本
expandedRowsChange展开的行变化时触发Function(expandedRows)
change分页、排序、筛选变化时触发Function(pagination, filters, sorter, { action: 'paginate' | 'sort' | 'filter' })
expand点击展开图标时触发Function(expanded, record)
resizeColumn拖动列时触发, 如果不需要内部自动更改宽度,可以返回 falseFunction(width, column, action: 'start' | 'move' | 'end' ) => boolean | void2.0.3
rowDragEnd拖拽行结束时触发(opt: DragRowEventInfo) => boolean | Promise | void2.1.0
columnDragEnd拖拽列结束时触发(opt: DragColumnEventInfo) => boolean | Promise | void2.1.1

方法

事件名称说明参数版本
scrollTo滚动到指定位置, 优先级:left > columnIndex > columnKeyFunction(pos: {left?: number; top?: number; columnIndex?: number; columnKey?: Key; rowKey?: Key; }, behavior?: 'auto' | 'smooth')2.0.3

customRow 用法

适用于 customRow customCell customHeaderCell。遵循Vue jsx语法。

<Table
  customRow={(record) => {
    return {
      xxx... //属性
      onClick: (event) => {},       // 点击行
      onDblclick: (event) => {},
      onContextmenu: (event) => {},
      onMouseenter: (event) => {},  // 鼠标移入行
      onMouseleave: (event) => {}
    };
  }}
/>

Column

列描述数据对象,是 columns 中的一项,Column 使用相同的 API。

参数说明类型默认值版本
align设置列的对齐方式left | right | centerleft
autoHeight是否启用自动行高booleanfalse
colSpan表头列合并,设置为 0 时,不渲染number
dataIndex列数据在数据项中对应的路径,支持通过数组查询嵌套路径string | string[]-
defaultFilteredValue默认筛选值string[]-
defaultSortOrder默认排序顺序ascend | descend-
ellipsis超过宽度将自动省略。设置为 true 时,showTitle 默认为 trueboolean | { showTitle?: boolean }false
tooltip单元格是否显示 tooltip,它和 ellipsis.showTitle 是独立不相关的功能,tooltip 内容需要额外通过 tooltip.titilecellTooltip 插槽传递。设置为 true 时,使用 cellTooltip 内容。boolean | CellTooltipfalse
filterDropdown可以自定义筛选菜单,此函数只负责渲染图层,需要自行编写各种交互VNode-
customFilterDropdown启用 v-slot:customFilterDropdown,优先级低于 filterDropdownbooleanfalse
filterDropdownVisible用于控制自定义筛选菜单是否可见boolean-
filtered标识数据是否经过过滤,筛选图标会高亮booleanfalse
filteredValue筛选的受控属性,外界可用此控制列的筛选状态,值为已筛选的 value 数组string[]-
filterIcon自定义 filter 图标。VNode | ({filtered: boolean, column: Column}) => vNodefalse
filterMultiple是否多选booleantrue
filters表头的筛选菜单项object[]-
fixed列是否固定,可选 true(等效于 left) 'left' 'right'boolean|stringfalse
keyVue 需要的 key,如果已经设置了唯一的 dataIndex,可以忽略这个属性string-
customRender生成复杂数据的渲染函数,参数分别为当前行的值,当前行数据,行索引,@return 里面可以设置表格行/列合并,可参考 demo 表格行/列合并Function({text, record, index, column}) {}-
responsive响应式 breakpoint 配置列表。未设置则始终可见。Breakpoint[]-
showSorterTooltip表头显示下一次排序的 tooltip 提示, 覆盖 table 中 showSorterTooltipboolean | Tooltip propstrue
sorter排序函数,本地排序使用一个函数(参考 Array.sort 的 compareFunction),需要服务端排序可设为 trueFunction|boolean-
sortOrder排序的受控属性,外界可用此控制列的排序,可设置为 'ascend' 'descend' falseboolean|string-
sortDirections支持的排序方式,取值为 'ascend' 'descend'Array['ascend', 'descend']
title列头显示文字string-
width列宽度string|number-
minWidth拖动列最小宽度,会受到表格自动调整分配宽度影响number50
maxWidth拖动列最大宽度,会受到表格自动调整分配宽度影响number-
resizable是否可拖动调整宽度,此时 width 必须是 number 类型, 仅支持叶子结点boolean-
customCell设置单元格属性Function(obj: {record: any; rowIndex: number; column: ColumnType})-
customHeaderCell设置头部单元格属性Function(column)-
onFilter本地模式下,确定筛选的运行函数, 使用 template 或 jsx 时作为filter事件使用Function-
onFilterDropdownVisibleChange自定义筛选菜单可见变化时调用,使用 template 或 jsx 时作为filterDropdownVisibleChange事件使用function(visible) {}-
rowDrag当前列添加拖拽手柄, 详见boolean | (arg: { record: RecordType; column: ColumnType }) => boolean-2.1.0
drag列表头是否允许拖拽, 详见boolean-2.1.1

Breakpoint

export type Breakpoint = 'xxl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs'

CellTooltip

export interface CellTooltip {
  placement?: 'top' | 'left' | 'right' | 'bottom' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'leftTop' | 'leftBottom' | 'rightTop' | 'rightBottom'
  color?: String
  overlayStyle?: CSSProperties
  overlayClassName?: String
  openClassName?: String
  title?: (args: CellRenderArgs) => any
  align?: TooltipAlignConfig
}

RowDragGhostArg

interface DragRowsHandleInfo {
  y: number
  top: number
  height: number
  rowKey: Key
  centerY: number
  record: DefaultRecordType
  indexs: number[] // 这是一个索引数组,用以支持树形结构
}

export interface RowDragGhostArg<RecordT, ColumnT> {
  record: RecordT
  column: ColumnT
  icon: VNode
  allowed: boolean
  dragging: boolean
  event: MouseEvent | Touch
  preTargetInfo: DragRowsHandleInfo | null
  nextTargetInfo: DragRowsHandleInfo | null
}

DragRowEventInfo

export interface DragRowEventInfo {
  top: number
  height: number
  record: DefaultRecordType
  dir: 'down' | 'up'
  rowKey: Key
  event: MouseEvent | Touch
  column: ColumnType
  preTargetInfo: DragRowsHandleInfo | null
  nextTargetInfo: DragRowsHandleInfo | null
  fromIndexs: number[] // 这是一个索引数组,用以支持树形结构
  insertToRowKey: Key
}

DragColumnEventInfo

export interface DragColumnEventInfo {
  event: MouseEvent | Touch
  column: ColumnType
  targetColumn: ColumnType
  dir: 'left' | 'right'
}

ColumnDragGhostArg

export interface ColumnDragGhostArg<ColumnT> {
  column: ColumnT
  icon: VNode
  allowed: boolean
  dragging: boolean
  event: MouseEvent | Touch
  targetColumn: ColumnT
}

ColumnGroup

参数说明类型默认值
title列头显示文字string|slot-

loading

参数说明类型默认值
delay延迟显示加载效果的时间(防止闪烁)number (毫秒)-
indicator加载指示符vNode | slot-
size组件大小,可选值为 small default largestring'default'
spinning是否为加载中状态booleantrue
tip当作为包裹元素时,可以自定义描述文案string-
wrapperClassName包装器的类属性string-

tooltip

参数说明类型默认值
arrowPointAtCenter箭头是否指向目标元素中心booleanfalse
autoAdjustOverflow气泡被遮挡时自动调整位置booleantrue
color背景颜色string
defaultVisible默认是否显隐booleanfalse
getPopupContainer浮层渲染父节点,默认渲染到 body 上Function(triggerNode)() => document.body
mouseEnterDelay鼠标移入后延时多少才显示 Tooltip,单位:秒number0.1
mouseLeaveDelay鼠标移出后延时多少才隐藏 Tooltip,单位:秒number0.1
overlayClassName卡片类名string
overlayStyle卡片样式object
placement气泡框位置,可选 top left right bottom topLeft topRight bottomLeft bottomRight leftTop leftBottom rightTop rightBottomstringtop
trigger触发行为,可选 hover/focus/click/contextmenustringhover
visible用于手动控制浮层显隐booleanfalse
destroyTooltipOnHide隐藏后是否销毁 tooltipbooleanfalse
align该值将合并到 placement 的配置中,设置参考 dom-alignObject
onVisibleChange显示隐藏的回调(visible) => void

pagination

分页的配置项。

参数说明类型默认值版本
position指定分页显示的位置, 取值为topLeft | topCenter | topRight |bottomLeft | bottomCenter | bottomRightArray[bottomRight]
current当前页数number-
pageSize每页条数number-
defaultPageSize默认的每页条数number10
disabled禁用分页boolean-
hideOnSinglePage只有一页时是否隐藏分页器booleanfalse
itemRender用于自定义页码的结构,可用于优化 SEO({page, type: 'page' | 'prev' | 'next', originalElement}) => vNode-
pageSizeOptions指定每页可以显示多少条string[]['10', '20', '30', '40']
showLessItems是否显示较少页面内容booleanfalse
showQuickJumper是否可以快速跳转至某页booleanfalse
showSizeChanger是否可以改变 pageSizebooleanfalse
showTotal用于显示数据总量和当前数据顺序Function(total, range)-
simple当添加该属性时,显示为简单分页boolean-
size当为「small」时,是小尺寸分页string""
total数据总数number0
onChange页码改变的回调,参数是改变后的页码及每页条数Function(page, pageSize)noop
onShowSizeChangepageSize 变化的回调Function(current, size)noop

rowSelection

选择功能的配置。

参数说明类型默认值版本
checkStrictlycheckable 状态下节点选择完全受控(父子数据选中状态不再关联)booleantrue
columnWidth自定义列表选择框宽度string|number-
columnTitle自定义列表选择框标题string|VNode| () => VNode-2.4.6
fixed把选择框列固定在左边boolean-
allowCancelRadio是否允许取消单选boolean-2.1.0
getCheckboxProps选择框的默认属性配置Function(record)-
hideSelectAll隐藏全选勾选框与自定义选择项booleanfalse
preserveSelectedRowKeys当数据被删除时仍然保留选项的 keyboolean-
hideDefaultSelections去掉『全选』『反选』两个默认选项booleanfalse
selectedRowKeys指定选中项的 key 数组,需要和 onChange 进行配合string[][]
selections自定义选择项 配置项, 设为 true 时使用默认选择项object[] | booleantrue
type多选/单选,checkbox or radiostringcheckbox
onChange选中项发生变化时的回调Function(selectedRowKeys, selectedRows)-
onSelect用户手动选择/取消选择某列的回调Function(record, selected, selectedRows, nativeEvent)-
onSelectAll用户手动选择/取消选择所有列的回调Function(selected, selectedRows, changeRows)-
onSelectInvert用户手动选择反选的回调Function(selectedRows)-
onSelectNone用户清空选择的回调function()-

scroll

参数说明类型默认值
scrollToFirstRowOnChange当分页、排序、筛选变化后是否滚动到表格顶部boolean-
x设置横向滚动,也可用于指定滚动区域的宽,可以设置为像素值,百分比,true 和 'max-content'string | number | true-
y设置纵向滚动,也可用于指定滚动区域的高,可以设置为像素值string | number-

selection

自定义选择配置项

参数说明类型默认值版本
keyVue 需要的 key,建议设置string-
text选择项显示的文字string|VNode | ()=> VNode (2.4.6+)-
onSelect选择项点击回调Function(changeableRowKeys)-

FilterDropdownProps

interface FilterDropdownProps {
  prefixCls: string
  setSelectedKeys: (selectedKeys: Key[]) => void
  selectedKeys: Key[]
  confirm: (param?: FilterConfirmProps) => void
  clearFilters?: () => void
  filters?: ColumnFilterItem[]
  visible: boolean
  column: ColumnType
}

注意

在 Table 中,dataSourcecolumns 里的数据值都需要指定 key 值。对于 dataSource 默认将每列数据的 key 属性作为唯一的标识。

如果你的数据没有这个属性,务必使用 rowKey 来指定数据列的主键。若没有指定,控制台会出现缺少 key 的提示,表格组件也会出现各类奇怪的错误。

// 比如你的数据主键是 uid
return <Table rowKey="uid" />
// 或
return <Table rowKey={(record) => record.uid} />