vxe-table
![npm license](https://img.shields.io/github/license/mashape/apistatus.svg)
A very powerful Vue table component.
Features
Installing
npm install xe-utils vxe-table
Get on unpkg and cdnjs
<link rel="stylesheet" href="https://unpkg.com/vxe-table/lib/index.css">
<script src="https://unpkg.com/xe-utils"></script>
<script src="https://unpkg.com/vxe-table"></script>
import Vue from 'vue'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
Vue.use(VXETable)
API
Table
<vxe-table :data.sync="tableData">
<vxe-table-column type="selection" width="60"></vxe-table-column>
<vxe-table-column prop="name" label="Name"></vxe-table-column>
<vxe-table-column prop="address" label="Address"></vxe-table-column>
</vxe-table>
Table Attributes
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|
data | 显示的数据 | Array | — | — |
customs | 初始化绑定动态列 | Array | — | — |
height | 表格的高度 | Number | — | — |
maxHeight | 表格的最大高度 | Number | — | — |
stripe | 是否带有斑马纹 | Boolean | — | false |
border | 是否带有纵向边框 | Boolean | — | false |
size | 表格的尺寸 | String | medium / small / mini | — |
fit | 列的宽度是否自撑开 | Boolean | — | true |
loading | 表格是否加载中 | Boolean | — | false |
show-header | 是否显示表头 | Boolean | — | true |
highlight-current-row | 是否要高亮当前选中行 | Boolean | — | false |
highlight-hover-row | 鼠标移到行是否要高亮显示 | Boolean | — | true |
row-class-name | 给行附加 className,也可以是函数 Function({row, rowIndex}) | String/Function | — | — |
cell-class-name | 给单元格附加 className,也可以是函数 Function({row, rowIndex, column, columnIndex}) | String/Function | — | — |
header-row-class-name | 给表头的行附加 className,也可以是函数 Function({row, rowIndex}) | String/Function | — | — |
header-cell-class-name | 给表头的单元格附加 className,也可以是函数 Function({row, rowIndex, column, columnIndex}) | String/Function | — | — |
context-menu | 快捷菜单配置 | Object | — | {header, body} |
row-key | 行数据的 Key | String | — | — |
auto-width | 自动计算列宽(如果关闭,需要手动调用 computeWidth 方法) | Boolean | — | true |
optimized | 优化的配置项 | Object/Boolean | — | {animat: true, overflow: 'title'} |
快捷菜单配置项说明(配合 context-menu-link 事件使用):
属性 | 描述 | 类型 | 参数 |
---|
disabled | 是否禁用表格头部右键 | Boolean | — |
options | 表格头部菜单配置 | Array | { code, name, prefixIcon, suffixIcon, disabled } |
visibleMethod | 该函数 Function({row, rowIndex, column, columnIndex}, event) 的返回值用来决定是否允许显示右键菜单 | Function | — |
Table Events
事件名 | 说明 | 参数 |
---|
select-all | 只对 type=selection 有效,当手动勾选全选时触发的事件 | {selection,checked},event |
select-change | 只对 type=selection/radio 有效,当手动勾选时触发的事件 | {selection,checked,row,column},event |
cell-click | 当某个单元格被点击时会触发该事件 | {row,rowIndex,column,columnIndex,cell},event |
cell-dblclick | 当某个单元格被双击时会触发该事件 | {row,rowIndex,column,columnIndex,cell},event |
context-menu-link | 当点击上下文菜单后触发 | menu,event |
Table Methods
方法名 | 描述 | 参数 |
---|
reload | 初始化数据 | data |
clearSelection | 用于多选表格,清空用户的选择 | — |
clearSelectRow | 用于单选表格,清空用户的选择 | — |
clearSort | 用于清空排序条件,数据会恢复成未排序的状态 | — |
clearFilter | 用于清空筛选条件,数据会恢复成未筛选的状态 | — |
computeWidth | 重新计算并更新列宽 | — |
Table-column
<vxe-table-column prop="name" label="Name"></vxe-table-column>
Table-column Attributes 参数
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|
type | 列的类型 | String | index / selection / radio | — |
prop | 列属性 | String | — | — |
label | 列标题 | String | — | — |
width | 列宽度 | String | — | — |
min-width | 最小列宽度,把剩余宽度按比例分配 | String | — | — |
fixed | 将列固定在左侧或者右侧 | String | — | left |
align | 列对其方式 | String | — | left |
header-align | 表头对齐方式 | String | — | — |
ellipsis | 当内容过长时显示为省略号 | Boolean | — | false |
show-overflow-title | 当内容过长显示为省略号并用原生的 title 显示完整内容 | Boolean | — | false |
show-overflow-tooltip | 当内容过长显示为省略号并用 tooltip 显示完整内容 | Boolean | — | false |
formatter | 格式化显示内容 Function({cellValue, row, rowIndex, column, columnIndex}) | Function | — | — |
index-method | 只对 type=index 有效,自定义索引方法 Function({row, rowIndex, column, columnIndex}) | Function | — | — |
sortable | 是否允许列排序 | Boolean | — | — |
sortBy | 只对 sortable 有效,自定义排序的属性 | String/Array | — | — |
filters | 配置筛选条件数组 | Array | — | — |
filter-multiple | 只对 filters 有效,筛选是否允许多选 | Boolean | — | true |
filter-method | 只对 filters 有效,自定义筛选方法 Function({value, row, column}) | Function | — | — |
column-key | 列的 key | [String, Number] | — | — |
Table-column Scoped Slot
name | 说明 |
---|
— | 自定义显示内容,参数为 { row, rowIndex, column, columnIndex, fixed, isHidden } |
header | 自定义表头的内容,参数为 { column, columnIndex, fixed, isHidden } |
Example
<template>
<div>
<vxe-table :data.sync="tableData">
<vxe-table-column type="index" width="60"></vxe-table-column>
<vxe-table-column prop="name" label="Name"></vxe-table-column>
<vxe-table-column prop="sex" label="Sex"></vxe-table-column>
<vxe-table-column prop="address" label="Address"></vxe-table-column>
</vxe-table>
</div>
</template>
<script>
export default {
data () {
return {
tableData: [
{
id: 10001,
checked: false,
name: 'test1',
role: 'developer',
sex: 'Man',
date: '2019-05-01',
time: 1556677810888,
region: 'ShenZhen',
address: 'address abc123'
}
]
}
}
}
</script>
License
Copyright (c) 2017-present, Xu Liangzhan