1.0.15 • Published 3 years ago

excel-table-vue v1.0.15

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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

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

截图

image

image

特性

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

安装

npm install excel-table-vue --save

挂载

挂载在全局

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

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

Vue.component('vueExcelTable', vueExcelTable)

挂载在组件

import vueExcelTable from 'excel-table-vue'

// require styles
import 'excel-table-vue/dist/excel-table-vue.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: '月份',
          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);
    },
  },
};
</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})————

事件

事件名称说明回调参数
selection-change当选择项发生变化时会触发该事件selection

方法

方法名说明参数
getData用来获取数据,返回当前表格数据——
setData用来设置数据,并重置历史记录data
getChangeData获取变化的数据行——
getErrorRows获取校验错误的数据和索引——
addItem添加一行数据item, type(默认'push',可选'unshift')
removeItems批量删除,参数key为每行的唯一标识属性如id,values为该标识属性的数组key, values

列属性

参数说明类型可选值默认值
key对应列内容的字段名String————
title列头显示文字String————
width列宽度String / Number————
type列类型Stringselection/number/date/select/month——
format千分号格式(用于number类型)Boolean——true
optionsselect下拉选项Array{ value: '值', label: '显示文字' }——
fixed是否固定在左侧Boolean——false
action是否启用筛选和排序Boolean——false
disabled是否禁止编辑Boolean——false
noVerify是否禁用校验Boolean——false
validate自定义校验Function(value)————

快捷键

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

// TODO security vulnerabilities

1.0.2

3 years ago

1.0.11

3 years ago

1.0.15

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.1

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.0

3 years ago