最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

hansontable在vue中的基本使用教程

 更新時間:2022年10月27日 11:22:29   作者:遠方除了遙遠一無所有  
handsontable是目前在前端界最接近excel的插件,可以執(zhí)行編輯,復制粘貼,插入刪除行列,排序等復雜操作,這篇文章主要介紹了hansontable在vue中的基本使用,需要的朋友可以參考下

簡介

Vue Handsontable是一個具有Spreadsheet外觀的Vue數(shù)據(jù)表格組件,是Handsontable的官方封裝。 Handsontable易于與任何數(shù)據(jù)源集成,并具有許多有用的功能,如數(shù)據(jù)綁定、驗證、排序和強大的上下文菜單。

特點

  • 多列排序
  • 非連續(xù)選擇
  • 過濾數(shù)據(jù)
  • 導出文件
  • 驗證數(shù)據(jù)
  • 條件格式
  • 合并單元格
  • 自定義單元格類型
  • 凍結(jié)行/列
  • 移動行/列
  • 調(diào)整大小行/列
  • 隱藏行/列
  • 上下文菜單
  • 注釋
  • 自動填充選項

handsontable是目前在前端界最接近excel的插件,可以執(zhí)行編輯,復制粘貼,插入刪除行列,排序等復雜操作

代碼

Test.vue

<template>
  <div id="hansontable">
    <hot-table
      :data="data"
      :settings="hotSettings"
      ref="hotTableRef"
    ></hot-table>
  </div>
</template>

<script>
import Handsontable from 'handsontable'
import { HotTable } from '@handsontable/vue'
import 'handsontable/dist/handsontable.full.css'
import { registerAllModules } from 'handsontable/registry'

// register Handsontable's modules
registerAllModules()

import hotSettings from './hotSettings'

export default {
  components: {
    HotTable,
  },
  data() {
    return {
      // data: Handsontable.helper.createSpreadsheetData(10, 7),
      data: [
        { car: 'Tesla', year: 2017, chassis: 'black', bumper: 'black' },
        { car: 'Nissan', year: 2018, chassis: 'blue', bumper: 'blue' },
        { car: 'Chrysler', year: 2019, chassis: 'yellow', bumper: 'black' },
        { car: 'Volvo', year: 2020, chassis: 'white', bumper: 'gray' },
      ],
      hotSettings,
      hotInstance: null,
    }
  },
  mounted() {
    // 獲取實例
    this.hotInstance = this.$refs.hotTableRef.hotInstance
    const getDataAtRowProp = this.hotInstance.getDataAtRowProp
    // 示例:只允許單元格值為2019的數(shù)據(jù)進行更改
    this.hotInstance.updateSettings({
      cells(row, col, prop) {
        const cellProperties = {}
        console.log(row, prop)
        if (getDataAtRowProp(row, prop) == 2019) {
          cellProperties.editor = false
        } else {
          cellProperties.editor = 'text'
        }
        return cellProperties
      },
    })
  },
}
</script>

<!-- 注意:這里不能加"scoped",否則表頭的背景顏色無法設置 -->
<style>
.make-me-red {
  color: red;
}
.custom-table thead th {
  background-color: #d7f1e1;
}
</style>

hotSettings.js

import Handsontable from 'handsontable'

Handsontable.renderers.registerRenderer(
  'negativeValueRenderer',
  negativeValueRenderer
)

function negativeValueRenderer(
  instance,
  td,
  row,
  col,
  prop,
  value,
  cellProperties
) {
  Handsontable.renderers.TextRenderer.apply(this, arguments)

  // 示例1:如果單元格的值小于10,則添加類名
  if (parseInt(value, 10) < 0) {
    td.className = 'make-me-red'
  }

  // 如果單元格的值為空或者沒值
  if (!value || value === '') {
    td.style.background = '#EEE'
  } else {
    if (value === 'Nissan') {
      td.style.fontStyle = 'italic'
    }

    td.style.background = ''
  }
}

function firstRowRenderer(instance, td, row, col, prop, value, cellProperties) {
  Handsontable.renderers.TextRenderer.apply(this, arguments)
  td.style.fontWeight = 'bold'
  td.style.color = 'green'
  td.style.background = 'orange'
}

const hotSetting = {
  licenseKey: 'non-commercial-and-evaluation',
  // colHeaders: true,
  // 列合并
  //    注意:在第一列的表頭是不能合并的
  // nestedHeaders: [
  //   ['Car', { label: 'Year', colspan: 5 }, 'Chassis color', 'Bumper color'],
  //   [
  //     'Country',
  //     { label: 'City', colspan: 3 },
  //     'Address',
  //     'Zip code',
  //     'MobileH',
  //   ],
  // ],
  // 列名
  colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'],
  // rowHeaders: true,
  rowHeights: 40,
  width: '100%',
  // height: 'auto',
  height: 400,
  // 是否可以手動調(diào)整列大小
  manualColumnResize: true,
  // 將所有的列平均拉伸到父容器的寬度
  stretchH: 'all',
  // 右鍵下拉菜單
  // dropdownMenu: true,
  filters: true,
  dropdownMenu: ['filter_by_condition', 'filter_by_value', 'filter_action_bar'],
  // 列排序
  columnSorting: true,
  // 單元格的合并
  mergeCells: [{ row: 0, col: 0, rowspan: 2, colspan: 2 }],
  // 設置單元格的水平和垂直居中,并為表格添加自定義的類名
  className: 'htCenter htMiddle custom-table',
  // 單元格樣式設置
  cells(row, col) {
    const cellProperties = {}

    // 對第一行設置樣式,注意:不包括表頭
    //     方式1: 直接通過函數(shù)
    //     方式2: 字符串,通過hansontable的map映射使用渲染器
    if (row === 0) {
      cellProperties.renderer = firstRowRenderer // uses function directly
    } else {
      cellProperties.renderer = 'negativeValueRenderer'
    }
    return cellProperties
  },
  // 是否只讀
  // readOnly: true,
}

export default hotSetting

效果圖

參考文檔

https://juejin.cn/post/7062875824730406919

https://www.cnblogs.com/my-secret-base/p/13390054.html

https://www.jianshu.com/p/924481947c30

到此這篇關于hansontable在vue中的基本使用的文章就介紹到這了,更多相關vue  hansontable使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

阳曲县| 岳普湖县| 吉水县| 湟源县| 嵊泗县| 蓬安县| 荣成市| 无为县| 固始县| 怀仁县| 兴和县| 新安县| 遂平县| 北川| 确山县| 嘉禾县| 漳州市| 临沭县| 禄丰县| 文山县| 宁明县| 南丹县| 潍坊市| 余庆县| 怀宁县| 江达县| 寿光市| 怀来县| 浦江县| 衡山县| 苏尼特右旗| 志丹县| 阿尔山市| 海南省| 鄂托克旗| 石门县| 孝义市| 南昌市| 卢氏县| 綦江县| 乌苏市|