1.0.1 • Published 7 months ago

vue-vtable-grid v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Vue-Vtable-Grid

  • 😊 基于 Vue 2.0 开发;
  • 👍 使用 VTable

安装

npm i vue-vtable-grid -S
# OR
yarn add vue-vtable-grid -S

全局使用

// main.js
import Vue from 'vue';
import App from './App.vue';
// ...
import vueVtableGrid from 'vue-vtable-grid';
Vue.use(vueVtableGrid);
// ...
new Vue({
  el: '#app',
  render: (h) => h(App),
});
<template>
  <div id="app">
    <vue-vtable-grid
      ref="table"
      @click-cell="clickCell"
      :records="records"
      :columns="columns"
      :options="options"
    />
  </div>
</template>

<script>
const generatePersons = (count) => {
  return Array.from(new Array(count)).map((_, i) => ({
    id: i + 1,
    email1: `${i + 1}@xxx.com`,
    name: `小明${i + 1}`,
    lastName: '王',
    date1: '2022年9月1日',
    tel: '000-0000-0000',
    sex: i % 2 === 0 ? 'boy' : 'girl',
    work: i % 2 === 0 ? 'back-end engineer' : 'front-end engineer',
    city: 'beijing',
  }));
};
export default {
  name: 'App',
  components: {
    // vtableGrid,
  },
  data() {
    return {
      records: [],
      columns: [
        {
          field: 'id',
          title: 'ID ff',
          width: '1%',
          minWidth: 200,
          sort: true,
        },
        {
          field: 'email1',
          title: 'email',
          width: 200,
          sort: true,
        },
        {
          field: 'date1',
          title: 'birthday',
          width: 200,
        },
        {
          field: 'sex',
          title: 'sex',
          width: 100,
        },
        {
          field: 'tel',
          title: 'telephone',
          width: 150,
        },
        {
          field: 'work',
          title: 'job',
          width: 200,
        },
        {
          field: 'city',
          title: 'city',
          width: 150,
        },
      ],
      options: {},
    };
  },
  methods: {
    clickCell(obj) {
      console.log(obj);
    },
  },
  created() {
    this.records = generatePersons(100000);
    this.options = {
      dragHeaderMode: 'all',
    };
  },
};
</script>
<style>
* {
  margin: 0;
  padding: 0;
}
html,
body {
  width: 100%;
  height: 100%;
}
#app {
  width: 100%;
  height: 100%;
}
</style>

局部引入

基本用法

<template>
  <div id="app">
    <vue-vtable-grid
      ref="table"
      @click-cell="clickCell"
      :records="records"
      :columns="columns"
      :options="options"
    />
  </div>
</template>

<script>
import vueVtableGrid from 'vue-vtable-grid';
const generatePersons = (count) => {
  return Array.from(new Array(count)).map((_, i) => ({
    id: i + 1,
    email1: `${i + 1}@xxx.com`,
    name: `小明${i + 1}`,
    lastName: '王',
    date1: '2022年9月1日',
    tel: '000-0000-0000',
    sex: i % 2 === 0 ? 'boy' : 'girl',
    work: i % 2 === 0 ? 'back-end engineer' : 'front-end engineer',
    city: 'beijing',
  }));
};
export default {
  name: 'App',
  components: {
    vueVtableGrid,
  },
  data() {
    return {
      records: [],
      columns: [
        {
          field: 'id',
          title: 'ID ff',
          width: '1%',
          minWidth: 200,
          sort: true,
        },
        {
          field: 'email1',
          title: 'email',
          width: 200,
          sort: true,
        },
        {
          field: 'date1',
          title: 'birthday',
          width: 200,
        },
        {
          field: 'sex',
          title: 'sex',
          width: 100,
        },
        {
          field: 'tel',
          title: 'telephone',
          width: 150,
        },
        {
          field: 'work',
          title: 'job',
          width: 200,
        },
        {
          field: 'city',
          title: 'city',
          width: 150,
        },
      ],
      options: {},
    };
  },
  methods: {
    clickCell(obj) {
      console.log(obj);
    },
  },
  created() {
    this.records = generatePersons(100000);
    this.options = {
      dragHeaderMode: 'all',
    };
  },
};
</script>
<style>
* {
  margin: 0;
  padding: 0;
}
html,
body {
  width: 100%;
  height: 100%;
}
#app {
  width: 100%;
  height: 100%;
}
</style>

属性

参数说明类型可选值默认值
width表格宽度String100%
height表格高度String100%
records表格数据,详见recordsArray
columns表格列,,详见columnsArray
options表格配置项,详见optionsObject

事件

详细参数见:Events

事件名说明参数
click-cell鼠标点击单元格事件
dblclick-cell鼠标双击单元格事件
mousedown-cell单元格上鼠标按下事件
mouseup-cell单元格鼠标松开事件
selected-cell单元格选中状态改变事件
keydown键盘按下事件
mouseenter-table鼠标进入表格事件
mouseleave-table鼠标离开表格事件
mousemove-cell鼠标在某个单元格上移动事件
mouseenter-cell鼠标进入单元格事件
mouseleave-cell鼠标离开单元格事件
contextmenu-cell单元格右键事件
resize-column列宽调整事件
resize-column-end列宽调整结束事件
change-header-position拖拽表头移动位置的事件
sort-click点击排序图标事件
freeze-click点击固定列图标冻结或者解冻事件
scroll滚动表格事件
dropdownmenu-click点击下拉菜单图标事件
mouseover-chart-symbol鼠标经过迷你图标记事件
drag-select-end拖拽框选单元格鼠标松开事件
dropdown-icon-click点击下拉菜单按钮
dropdown-menu-clear清空下拉菜单事件(菜单显示时点击其他区域)
tree-hierarchy-state-change树形结构展开收起的点击事件
show-menu显示菜单事件
hide-menu隐藏菜单事件
icon-clickicon 图标点击事件
drillmenu-click下钻按钮点击事件。透视表专有事件
pivot-sort-click透视表中排序图标点击事件。透视表专有事件
legend-item-click图例项点击事件。图例专有事件
legend-item-hover图例项 hover 事件。图例专有事件
legend-item-unhover图例项 hover 到 unhover 事件。图例专有事件
legend-change颜色图例,尺寸图例,用户操作图例范围后触发该事件。图例专有事件
mouseenter-axis鼠标进入到坐标轴上事件。坐标轴专有事件
mouseleave-axis鼠标离开坐标轴事件。坐标轴专有事件

方法

详细参数见:Methods

事件名说明参数
updateOption更新表格配置项,调用后会自动重绘options
updateTheme更新表格主题,调用后会自动重绘theme
updateColumns更新表格的 columns 字段配置信息,调用后会自动重绘。columns
updatePagination更新页码配置信息pagination
release销毁表格实例
selectCell选中某个单元格col, row
selectCells选中一个或者多个单元格区域[]
getCellStyle获取某个单元格的样式col, row
getAllCells获取所有单元格上下文信息colMaxCount, rowMaxCount
getAllBodyCells获取所有 body 单元格上下文信息colMaxCount, rowMaxCount
getAllColumnHeaderCells获取所有列表头单元格上下文信息colMaxCount, rowMaxCount
getAllRowHeaderCells获取所有行表头单元格上下文信息colMaxCount, rowMaxCount
getCellOverflowText获取有省略文字的的单元格文本内容col, row
getCellHeaderPaths获取行列表头的路径col, row
getCellAddress根据数据和 field 属性字段名称获取 body 中某条数据的行列号findTargetRecord, field
getCellAddressByHeaderPaths针对透视表格的接口,根据要匹配表头维度路径来获取具体的单元格地址dimensionPaths
scrollToCell滚动到具体某个单元格位置cellAddr
updateSortState更新排序状态sortState, executeSort
updatePivotSortState更新排序状态,PivotTable 专有pivotSortStateConfig
setDropDownMenuHighlight设置下拉菜单选中状态
showTooltip显示 tooltip 信息提示框col, row, tooltipOptions
updateFilterRules更新数据过滤规则filterRules
exportImg导出表格中当前可视区域的图片
exportCellImg导出某个单元格图片col, row
exportCellRangeImg导出某一片单元格区域的图片[]
1.0.1

7 months ago

1.0.0

7 months ago