vue.js 表格_Vue.js中更简单的电子表格

vue.js 表格

VueJs电子表格 (VueJs Spreadsheet)

An easier Spreadsheet in Vue.js

Vue.js中更简单的电子表格

Do not hesitate to :star: my repo

不要犹豫:star:我的仓库

项目设置 (Project setup)

yarn add vuejs-spreadsheet

npm i vuejs-spreadsheet
<script>
  import VueTable from 'vuejs-spreadsheet';
  export default {
    name: 'app',
    data() {
    },
    components: {
      VueTable,
    },
  };
</script>

维基:mortar_board: (Wiki :mortar_board:)

PropsTypeDescription
:tbody-dataArrayThat contains data
:headersArrayThat contains headers
:custom-optionsObjectThat contains Options
:style-wrap-vue-tableObjectThat contains style of the wrapper tableVue
:disable-cellsArrayThat contains the headerKey you want to disable
:disable-sort-theadArrayThat contains the disabled th
:loadingBooleanTrue => Hidden TbodyData / show slot loader
:parent-scroll-elementObjectThat contains the HTML attribute which overflow-y: scroll (by-default is 'html')
道具 类型 描述
:tbody-data 数组 包含数据
:标题 数组 包含标题
:自定义选项 目的 包含选项
:style-wrap-vue-table 目的 包含包装器表的样式
:disable-cells 数组 包含要禁用的headerKey
:disable-sort-thead 数组 包含残疾人的
:加载 布尔型 True =>隐藏的TbodyData / show slot loader
:父滚动元素 目的 包含溢出-yHTML属性:滚动(默认为'html')
....                               |            | That contains a top and left position you want to add to the select

:select-position | Object | That contains a top and left position you want to add to the select :submenu-tbody | Array | That contains the submenu-tbody :submenu-thead | Array | That contains the submenu-thead

:select-position | 对象 包含要添加到select:submenu-tbody |中的顶部和左侧位置。 数组| 包含submenu-tbody:submenu-thead | 数组| 包含子菜单

OptionsTypeDescription
:fuse-optionsObjectThat contains an object of fuse configuration look on her website: http://fusejs.io/
:new-dataObjectThat contains the type of data when you have empty cell in a row
:sort-headerBooleanThat activates sort button on header
:tbody-indexBooleanThat displays the index of each row on the left of the table
:tradObjectThat contains an object of translating
选件 类型 描述
:fuse-options 目的 该对象在她的网站上包含一个保险丝配置对象: http : //fusejs.io/
:新数据 目的 当您连续有空单元格时,它包含数据类型
:sort-header 布尔型 激活标题上的排序按钮
:tbody-index 布尔型 在表格左侧显示每一行的索引
:交易 目的 包含翻译的对象
FunctionTypeDescription
v-on:tbody-change-dataFunctionFired when data undergo modifications
v-on:tbody-input-changeFunctionWhen the input changes
v-on:tbody-select-changeFunctionWhen the select change
v-on:handle-up-drag-size-headerFunctionFired when the header size changed
v-on:thead-td-sortFunctionWhen you press the button sort
v-on:tbody-up-dragtofillFunctionFired when pressed up on dragToFill
v-on:tbody-move-dragtofillFunctionFired when moved on dragToFill
v-on:tbody-nav-backspaceFunctionWhen you press backspace on cell (event, actualElement, actualCol, rowIndex, colIndex)
v-on:tbody-nav-multiple-backspaceFunctionFired when the multiple cell are delete
v-on:tbody-submenu-click-{#}Function{#} - Name of the function declared on submenu-tbody
功能 类型 描述
v-on:车身更改数据 功能 数据修改后触发
v-on:本体输入更改 功能 输入改变时
v-on:本体选择更改 功能 选择改变时
v-on:处理拖曳大小标题 功能 标头大小更改时触发
v-on:thead-td-sort 功能 当您按按钮排序
v-on:tbody-up-dragtofill 功能 在dragToFill上按下时触发
v-on:tbody-move-dragtofill 功能 在dragToFill上移动时触发
v-on:tbody-nav-backspace 功能 当您在单元格上按退格键(事件,actualElement,actualCol,rowIndex,colIndex)
v-on:tbody-nav-multiple-backspace 功能 删除多个单元格时触发
v-on:tbody-submenu-click-{#} 功能 {#}-在submenu-tbody上声明的函数的名称
(Example)
<vue-table
    :tbody-data="Array"
    :headers="Array"
    :custom-options="Object"
    :style-wrap-vue-table="Object"
    :disable-cells="Array"
    :disable-sort-thead="Array"
    :loading="Boolean"
    :parent-scroll-element="Object"
    :select-position="Object"
    :submenu-tbody="Array"
    :submenu-thead="Array"
    v-on:tbody-change-data="changeData"
    v-on:tbody-submenu-click-change-color="changeColorTbody"
    v-on:tbody-submenu-click-change-value="changeValueTbody"
    v-on:thead-submenu-click-change-color="changeColorThead"
    v-on:thead-submenu-click-change-value="changeValueThead"
    v-on:thead-td-sort="sortProduct">

    // if your want to add an specific header
    <div slot="header">
      Specific Header
    </div>

    // if your want to add a loader
    <div slot="loader">
      Loader
    </div>
  </vue-table>

选项:蜜蜂: (Options :honeybee:)

customOptions: {
    dragToFill: true,
    tbodyIndex: true,
    sortHeader: true,
    trad: {
      lang: 'fr',
      en: {
        select: {
          placeholder: 'Search by typing',
        },
      },
      fr: {
        select: {
          placeholder: 'Taper pour chercher',
        },
      },
    },
    newData: {
      type: 'input',
      value: '',
      active: false,
      style: {
        color: '#000',
      },
    },
    fuseOptions: {
      shouldSort: true,
      threshold: 0.2,
      location: 0,
      distance: 30,
      maxPatternLength: 64,
      minMatchCharLength: 1,
      findAllMatches: false,
      tokenize: false,
      keys: [
        'value',
      ],
    },
  },

标题:老虎: (Headers :tiger:)

NameTypeDescription
headerNameStringThe chosen header name
headerkeyStringThe Slugify version of the headerName
styleObjectThe style of the td
名称 类型 描述
headerName 所选标题名称
标头键 标头名称的Slugify版本
样式 目的 TD的风格
- width         | String  | Indicate the width of ``<th>``
- minWidth      | String  | minWidth must be equal to width

disabled | Boolean | optional - Disabled cell

禁用 布尔| 可选-禁用的单元格

(Example)
headers: [
  {
    headerName: 'Image',
    headerKey: 'img',
    style: {
      width: '100px'
      minWidth: '100px'
    },
  },
  {
    headerName: 'Nom',
    headerKey: 'name',
    style: {
      width: '100px'
      minWidth: '100px'
    },
  },
  {
    headerName: 'Prénom',
    headerKey: 'surname',
    style: {
      width: '100px'
      minWidth: '100px'
    },
  },
  {
    headerName: 'Age',
    headerKey: 'age',
    style: {
      width: '100px'
      minWidth: '100px'
    },
  },
  {
    headerName: 'Born',
    headerKey: 'born',
    style: {
      width: '100px'
      minWidth: '100px'
    },
  },
],

数据:蜜蜂: (Data :honeybee:)

NameTypeDescription
keyStringThe key of the object written in Slugify
typeStringThe type of data rendered (<textarea>, <img>, <select>)
value(img/input)StringThe value of the object in String Type
value(select)ArrayThe value of the object in Array Type
selectOptionsArrayThat contains objects {value: ~, label: ~}
styleObjectThe Style of the cell
activeBooleanOf the cell, false by default
handleSearchBoolean- Activates search when selected
disabledBooleanoptional - Disabled cell
名称 类型 描述
用Slugify编写的对象的密钥
类型 呈现的数据类型( <textarea><img><select> )
值(img /输入) 字符串类型中对象的值
值(选择) 数组 数组类型中对象的值
selectOptions 数组 包含对象{值:〜,标签:〜}
样式 目的 单元格样式
活性 布尔型 单元格中,默认为false
handleSearch 布尔型 -选择后激活搜索
残障人士 布尔型 可选-禁用的单元格
(Example)
products: [
  {
    img: {
      type: 'img',
      value: 'https://via.placeholder.com/350x150',
      active: false,
      disabled: true,
    },
    name: {
      type: 'input',
      value: 'John',
      active: false,
      style: {
        color: '#000',
      },
    },
    surname: {
      type: 'input',
      value: 'Doe',
      active: false,
      style: {
        color: '#000',
      },
    },
    age: {
      type: 'select',
      handleSearch: true,
      selectOptions: [
        {
          value: 'paris',
          label: 'Paris',
        },
        {
          value: 'new-york',
          label: 'New York',
        },
      ],
      value: 'paris',
      active: false,
    },
    born: {
      type: 'select',
      handleSearch: true,
      selectOptions: [
        {
          value: 'france',
          label: 'France',
        },
        {
          value: 'usa',
          label: 'United States of America',
        },
      ],
      value: 'france',
      active: false,
    },
  },
],

新数据:老虎: (New Data :tiger:)

(Example)

Same Object describe on the top

同一对象在顶部描述

If you choose an input

如果选择输入

newData: {
  type: 'input',
  value: '',
  active: false,
  style: {
    color: '#000',
    background: '#cfffcf',
  },
},
NameTypeDescription
typeStringThe type of data rendered (<button>
valueStringThe value of the function
functionStringThe name of the function called when you click on the button - Written in Slugify
disabledArrayEach object which you want to hide on the submenu
subtitleStringOf the select
selectOptionsArrayThat contains objects {value: ~, label: ~}
buttonOptionObjectDescription
. valueStringThe value of the button
. functionStringThe name of the function called when you click on the button - Written in Slugify
. styleObjectThe style of the button
名称 类型 描述
类型 呈现的数据类型( <button>
函数的值
功能 单击按钮时调用的函数名称- 写在Slugify中
残障人士 数组 您要隐藏在子菜单上的每个对象
字幕 选择的
selectOptions 数组 包含对象{值:〜,标签:〜}
buttonOption 目的 描述
。 值 按钮的值
。 功能 单击按钮时调用的函数名称- 写在Slugify中
。 样式 目的 按钮的样式
(Example)
submenuTbody: [
    {
      type: 'button',
      value: 'Change Color',
      function: 'change-color',
      disabled: ['img'],
    },
  ],
  submenuThead: [ 
    {
      type: 'button',
      value: 'Change Color',
      function: 'change-color',
      disabled: ['img', 'name'],
    },
    {
      type: 'select',
      disabled: ['img'],
      subtitle: 'Select state:',
      selectOptions: [
        {
          value: 'new-york',
          label: 'new-york',
        },
        {
          value: 'france',
          label: 'france',
        },
      ],
      value: 'new-york',
      buttonOption: {
        value: 'change city',
        function: 'change-city',
        style: {
          display: 'block',
        },
      },
    },
  ],

例如:mortar_board::tiger: (Example :mortar_board: :tiger:)

<template>
  <div id="app">
    <vue-table
      :tbody-data="products"
      :headers="headers"
      :custom-options="customOptions"
      :style-wrap-vue-table="styleWrapVueTable"
      :disable-cells="disableCells"
      :disable-sort-thead="disableSortThead"
      :loading="loading"
      :parent-scroll-element="parentScrollElement"
      :select-position="selectPosition"
      :submenu-tbody="submenuTbody"
      :submenu-thead="submenuThead"
      v-on:tbody-change-data="changeData"
      v-on:tbody-submenu-click-change-color="changeColorTbody"
      v-on:tbody-submenu-click-change-value="changeValueTbody"
      v-on:thead-submenu-click-change-color="changeColorThead"
      v-on:thead-submenu-click-change-value="changeValueThead"
      v-on:thead-td-sort="sortProduct">
    <div slot="header">
      Specific Header
    </div>
    <div slot="loader">
      Loader
    </div>
    </vue-table>
  </div>
</template>

<script>

import VueTable from 'vuejs-spreadsheet';

export default {
  name: 'app',
  data() {
    return {
      customOptions: {
        tbodyIndex: true,
        sortHeader: true,
        trad: {
          lang: 'fr',
          en: {
            select: {
              placeholder: 'Search by typing',
            },
          },
          fr: {
            select: {
              placeholder: 'Taper pour chercher',
            },
          },
        },
        newData: {
          type: 'input',
          value: '',
          active: false,
          style: {
            color: '#000',
          },
        },
        fuseOptions: {
          shouldSort: true,
          threshold: 0.2,
          location: 0,
          distance: 30,
          maxPatternLength: 64,
          minMatchCharLength: 1,
          findAllMatches: false,
          tokenize: false,
          keys: [
            'value',
          ],
        },
      },
      submenuTbody: [
        {
          type: 'button',
          value: 'change color',
          function: 'change-color',
          disabled: ['img'],
        },
        {
          type: 'button',
          value: 'change value',
          function: 'change-value',
          disabled: ['img', 'name'],
        },
      ],
      submenuThead: [
        {
          type: 'button',
          value: 'change color',
          function: 'change-color',
          disabled: ['a'],
        },
        {
          type: 'select',
          disabled: ['a'],
          subtitle: 'Select state:',
          selectOptions: [
            {
              value: 'new-york',
              label: 'new-york',
            },
            {
              value: 'france',
              label: 'france',
            },
          ],
          value: 'new-york',
          buttonOption: {
            value: 'change city',
            function: 'change-city',
            style: {
              display: 'block',
            },
          },
        },
        {
          type: 'button',
          value: 'change value',
          function: 'change-value',
          disabled: ['a', 'b'],
        },
      ],
      disableCells: ['a'],
      loading: false,
      parentScrollElement: {
        attribute: 'html',
        positionTop: 0,
      },
      selectPosition: {
        top: 0,
        left: 0,
      },
      disableSortThead: ['a'],
      styleWrapVueTable: {
        color: '15px',
      },
      headers: [
        {
          headerName: 'A',
          headerKey: 'a',
          style: {
            width: '200px',
            minWidth: '200px',
            color: '#000',
          },
        },
        {
          headerName: 'B',
          headerKey: 'b',
          style: {
            width: '200px',
            minWidth: '200px',
            color: '#000',
          },
        },
        {
          headerName: 'C',
          headerKey: 'c',
          style: {
            width: '200px',
            minWidth: '200px',
            color: '#000',
          },
        },
        {
          headerName: 'D',
          headerKey: 'd',
          style: {
            width: '200px',
            minWidth: '200px',
            color: '#000',
          },
        },
        {
          headerName: 'E',
          headerKey: 'e',
          style: {
            width: '200px',
            minWidth: '200px',
            color: '#000',
          },
        },
        {
          headerName: 'F',
          headerKey: 'f',
          style: {
            width: '200px',
            minWidth: '200px',
            color: '#000',
          },
        },
        {
          headerName: 'G',
          headerKey: 'g',
          style: {
            width: '200px',
            minWidth: '200px',
            color: '#000',
          },
        },
      ],
      products: [
        {
          a: {
            type: 'img',
            value: 'https://via.placeholder.com/350x150',
            active: false,
          },
          c: {
            type: 'input',
            value: 'Paris',
            active: false,
            style: {
              color: '#000',
            },
          },
          d: {
            type: 'input',
            value: 'France',
            active: false,
            style: {
              color: '#000',
            },
          },
          e: {
            type: 'input',
            value: 'Boe',
            active: false,
            style: {
              color: '#000',
            },
          },
          f: {
            type: 'select',
            handleSearch: true,
            selectOptions: [
              {
                value: 'Harry Potter',
                label: 'harry potter',
              },
              {
                value: 'Hermione Granger',
                label: 'hermione granger',
              },
              {
                value: 'Ron Whisley',
                label: 'ron whisley',
              },
              {
                value: 'Dobby',
                label: 'dobby',
              },
              {
                value: 'Hagrid',
                label: 'hagrid',
              },
              {
                value: 'Professeur Rogue',
                label: 'professeur rogue',
              },
              {
                value: 'Professeur Mcgonagal',
                label: 'professeur mcgonagal',
              },
              {
                value: 'Professeur Dumbledor',
                label: 'professeur dumbledor',
              },
            ],
            value: 'professeur dumbledor',
            active: false,
          },
          g: {
            type: 'select',
            handleSearch: true,
            selectOptions: [
              {
                value: 1980,
                label: 1980,
              },
              {
                value: 1981,
                label: 1981,
              },
              {
                value: 1982,
                label: 1982,
              },
              {
                value: 1983,
                label: 1983,
                active: true,
              },
              {
                value: 1984,
                label: 1984,
              },
            ],
            value: 1983,
            active: false,
          },
        },
      ],
    };
  },
  components: {
    VueTable,
  },
  mounted() {
    this.loading = true;
    setTimeout(() => {
      this.loading = false;
    }, 300);
  },
  methods: {
    changeData(row, header) {
      console.log(row, header);
    },
    sortProduct(event, header, colIndex) {
      console.log('sort product');
    },
    // callback
    changeColorThead(event, header, colIndex) {
      this.headers[colIndex].style.color = '#e40000';
    },
    changeColorTbody(event, header, rowIndex, colIndex) {
      this.products[rowIndex][header].style = {};
      this.products[rowIndex][header].style.color = '#e40000';
    },
    changeValueTbody(event, header, rowIndex, colIndex) {
      this.products[rowIndex][header].value = 'T-shirt';
    },
    changeValueThead(event, entry, colIndex) {
      this.headers[colIndex].headerName = 'T-shirt';
    },
  },
};
</script>

<style lang="scss">
::-moz-selection {
  color: #2c3e50;
  background: transparent;
}
::selection {
  color: #2c3e50;
  background: transparent;
}
</style>

翻译自: https://vuejsexamples.com/an-easier-spreadsheet-in-vue-js/

vue.js 表格

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值