Socket
Socket
Sign inDemoInstall

vue-excel-table

Package Overview
Dependencies
20
Maintainers
6
Versions
84
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vue-excel-table

An excel table for Vue


Version published
Weekly downloads
109
increased by105.66%
Maintainers
6
Install size
4.74 MB
Created
Weekly downloads
 

Readme

Source

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关闭时取消键盘和鼠标事件监听

Keywords

FAQs

Last updated on 16 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc