3.1.28 • Published 2 years ago

vue-excel-table v3.1.28

Weekly downloads
13
License
MIT
Repository
github
Last release
2 years ago

vue-excel-table可编辑的表格组件

适用于Vue的可编辑的表格组件,支持多种快捷键操作,模拟Excel的操作体验

截图

image

image

特性

  • 表格宽度调整
  • 表格列固定
  • 数据筛选与排序
  • 行多选
  • 批量删除与复制粘贴
  • 可与Excel互相复制粘贴
  • 数据下拉复制
  • 下拉复制与多选单元格时候表格可自动滚动
  • 获取改变的数据行
  • 多种数据类型校验
  • 支持自定义规则数据校验
  • 获取校验非法的数据行
  • 支持撤销与重做
  • 可自定义每个单元格样式与类名
  • 使用局部渲染,支持更大量数据的展示
  • 自定义禁止行的某些列值进行修改
  • 单元格支持下拉多选情况
  • 单元格支持点击回调函数情况

安装

npm install vue-excel-table --save

挂载

挂载在全局

import Vue from 'vue'
import vueExcelTable from 'vue-excel-table'

// require styles
import 'vue-excel-table/dist/vue-excel-table.min.css'

Vue.component('vueExcelTable', vueExcelTable)

挂载在组件

import vueExcelTable from 'vue-excel-table'

// require styles
import 'vue-excel-table/dist/vue-excel-table.min.css'

export default {
  components: {
    vueExcelTable
  }
}

使用例子

<template>
  <excel-table
    ref="excelTable"
    :columns="columns"
    v-model="data"
    maxHeight="800" />
</template>

<script>
export default {
  data() {
    return {
      columns: [
        {
          type: 'selection',
          width: 40,
          fixed: true,
        },
        {
          title: '序号',
          key: 'sid',
          fixed: true,
          type: 'number',
          width: 100,
        },
        {
          title: '姓名',
          key: 'name',
          fixed: true,
          width: 120,
        },
        {
          title: '日期',
          key: 'date',
          type: 'date',
          width: 100,
        },
        {
          title: '工作岗位',
          key: 'email',
          width: 300,
          type: 'select',
          options: [
            {
              value: 'Web前端开发',
              label: 'Web前端开发',
            },
            {
              value: 'Java开发',
              label: 'Java开发',
            },
            {
              value: 'Python开发',
              label: 'Python开发',
            },
            {
              value: 'Php开发',
              label: 'Php开发',
            },
          ],
        },
        {
          title: '触发CallBack()',
          key: 'bbb',
          fixed: true,
          type: 'Link',
          width: 120,
          banClearSelected: true, // 禁止清空
          banAutofill: false, // 禁止下拉/上拉复制
          focusCallBackFunction: (cb) => {
            // eslint-disable-next-line no-alert
            const r = window.confirm('弹出窗口确认提示!');
            if (r === true) {
              console.warn('type is Link 注意: 如果是传入对象, 则表格会重置历史数据 Ctr + Z 记录清楚,即用不了/  回调做了一个clickoutsize() 即消除焦点解决某些问题');
              cb({ bbb: '填入值aaa', name: '填入值广州羽阳' });
              // cb('字符串aaa');
            } else {
              cb();
            }
          },
        },
        {
          title: '多选组件',
          key: 'aaa',
          width: 300,
          type: 'multipleSelect',
          options: [{
            value: 'unLimit',
            label: '无限制',
          }, {
            value: 'allSelect',
            label: '全选指定品牌',
          }, {
            value: 'Bmw',
            label: '宝马',
          }, {
            value: 'Bm2w',
            label: '宝马2',
          }],
        },
        {
          title: '月份',
          key: 'month',
          type: 'month',
          width: 100,
        },
        {
          title: '地址',
          key: 'address',
          width: 200,
        },
        {
          title: '标题',
          key: 'title',
          width: 300,
        },
        {
          title: '内容',
          key: 'paragraph',
          width: 300,
        },
        {
          title: '链接',
          key: 'url',
          width: 200,
        },
        {
          title: 'ip',
          key: 'ip',
          width: 200,
          validate: (value) => {
            const pattern = /((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/g;
            return pattern.test(value);
          },
        },
        {
          title: '总金额',
          key: 'sum',
          width: 200,
        },
        {
          title: 'ID',
          key: 'id',
          width: 200,
        },
        {
          title: '色值',
          key: 'color',
          width: 200,
        },
      ],
      data: [],
    },
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      const data = [];
      this.$refs.excelTable.setData(data);
    },
    autoDisableEditFunction4RowDataChanged(row) {
      return new Promise((reslove) => {
        if (row.email === '选项1') reslove([5, 6]);
        else reslove(false);
      });
    },
  },
};
</script>

数据

this.$refs.excelTable调用setData方法来更新整表数据,并会重置历史数据记录.

this.$refs.excelTable调用getData方法来获取整表数据.

v-model进行值的绑定

属性

参数说明类型可选值默认值
columns表格列的配置描述Array——[]
maxHeight表格最大高度string / number————
rowHeight每行高度string / number————
disabled是否禁止编辑Boolean——true
showIcon是否显示表头类型图标Boolean——false
cellStyle单元格的 style 的回调方法Function({row, column, rowIndex, columnIndex})————
cellClassName单元格的 className 的回调方法Function({row, column, rowIndex, columnIndex})————
disableRowEdit当双击编辑选择项或选中项的值将被修改时触发该事件Function(row)promise.reslove(false)或promise.reslove(0,1,2....)promise.reslove(false)
displaySelectLabel是否展示select的label (原来展示select的value)Boolean——false

事件

事件名称说明回调参数
selection-change当选择项发生变化时会触发该事件selection
editing当编辑结束时候触发该事件,返回编辑状态和单次所修改的行数据editState, changeData

方法

方法名说明参数
getData用来获取数据,返回当前表格数据——
setData用来设置数据,并重置历史记录data
getChangeData获取变化的数据行——
getErrorRows获取校验错误的数据和索引——
addItem添加一行数据item, type(默认'push',可选'unshift')
removeItems批量删除,参数key为每行的唯一标识属性如id,values为该标识属性的数组key, values
markCellError标记单元格错误,可使单元格颜色变红同时行的颜色变黄, 同一单元格触发多次是标记和取消标记切换sidName = 'sid'(用来判断找到行的唯一标识), sids = '1', '2', '3'(唯一标识数据), colomnKey = 'name', 'date'(标记行里哪些列需要标记的key)
clearMarkCellError主动清除某个错误单元格sidName = 'sid', sids = '1', '2', '3'
clearMarkCellErrorAll清空标记错误单元格

列属性

参数说明类型可选值默认值
key对应列内容的字段名String————
title列头显示文字String————
width列宽度String / Number————
type列类型Stringselection/number/date/select/month/Link/multipleSelect——
format千分号格式(用于number类型)Boolean——true
optionsselect下拉选项Array{ value: '值', label: '显示文字' }——
fixed是否固定在左侧Boolean——false
action是否启用筛选和排序Boolean——false
disabled是否禁止编辑Boolean——false
noVerify是否禁用校验Boolean——false
validate自定义校验Function(value)————
banClearSelected禁止清空Boolean————
banAutofill禁止下拉或上拉复制Boolean————
focusCallBackFunctionLink类型单元格时候生效,必填。功能是点击触发回调函数Function(callback)————

快捷键

快捷键说明
方向键移动编辑框
Ctrl + C粘贴
Ctrl + V复制
Ctrl + A单元格全选
Ctrl + Z撤销
Ctrl + Y重做
Enter单元格编辑/完成单元格编辑
Delete、Backspace删除

// TODO security vulnerabilities

Release History

VersionChanges
---新增Link 点击调用回调函数单元格类型
---新增下拉多选组件
3.1.2修复displaySelectLabel时候 select的title
3.1.1展示select的label
3.1.0关闭时取消键盘和鼠标事件监听
3.1.28

2 years ago

3.1.25

2 years ago

3.1.27

2 years ago

3.1.26

2 years ago

3.1.16

3 years ago

3.1.18

3 years ago

3.1.17

3 years ago

3.1.23

3 years ago

3.1.22

3 years ago

3.1.24

3 years ago

3.1.21

3 years ago

3.1.20

3 years ago

3.1.19

3 years ago

3.1.14

3 years ago

3.1.15

3 years ago

3.1.12

3 years ago

3.1.11

3 years ago

3.1.13

3 years ago

3.1.10

3 years ago

3.1.9

3 years ago

3.1.8

3 years ago

3.1.7

3 years ago

3.1.6

3 years ago

3.1.5

3 years ago

3.1.4

3 years ago

3.1.3

3 years ago

3.1.2

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.4

3 years ago

3.0.5

3 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.3

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

1.0.56

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.51

4 years ago

1.0.50

4 years ago

1.0.44

4 years ago

1.0.48

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.49

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.40

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.34

4 years ago

1.0.31

4 years ago

1.0.29

4 years ago

1.0.30

4 years ago

1.0.28

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.0

6 years ago