欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

hansontable在vue中的基本使用教程

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

簡介

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

特點(diǎn)

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

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

代碼

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() {
    // 獲取實(shí)例
    this.hotInstance = this.$refs.hotTableRef.hotInstance
    const getDataAtRowProp = this.hotInstance.getDataAtRowProp
    // 示例:只允許單元格值為2019的數(shù)據(jù)進(jìn)行更改
    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",否則表頭的背景顏色無法設(shè)置 -->
<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 }],
  // 設(shè)置單元格的水平和垂直居中,并為表格添加自定義的類名
  className: 'htCenter htMiddle custom-table',
  // 單元格樣式設(shè)置
  cells(row, col) {
    const cellProperties = {}

    // 對第一行設(shè)置樣式,注意:不包括表頭
    //     方式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

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

相關(guān)文章

  • Vue3基礎(chǔ)安裝以及配置詳解

    Vue3基礎(chǔ)安裝以及配置詳解

    這篇文章主要介紹了Vue3基礎(chǔ)安裝以及配置詳解,需要的朋友可以參考下
    2023-01-01
  • vue接入高德地圖繪制扇形效果的案例詳解

    vue接入高德地圖繪制扇形效果的案例詳解

    這篇文章主要介紹了vue接入高德地圖繪制扇形,需求是有一個列表,列表的數(shù)據(jù)就是一個基站信息,包含基站的經(jīng)緯度信息和名字,基站下面又分扇區(qū),本文通過示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-04-04
  • Vue中的路由跳轉(zhuǎn)及傳參的多種方法小結(jié)

    Vue中的路由跳轉(zhuǎn)及傳參的多種方法小結(jié)

    這篇文章主要介紹了Vue中的路由跳轉(zhuǎn)及傳參的多種方法小結(jié),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2023-11-11
  • vue3 獲取元素高度不準(zhǔn)的問題

    vue3 獲取元素高度不準(zhǔn)的問題

    這篇文章主要介紹了vue3 獲取元素高度不準(zhǔn)的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • element表格行列拖拽的實(shí)現(xiàn)示例

    element表格行列拖拽的實(shí)現(xiàn)示例

    本文主要介紹了element表格行列拖拽的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 如何在vue3中同時使用tsx與setup語法糖

    如何在vue3中同時使用tsx與setup語法糖

    這篇文章主要介紹了如何在vue3中同時使用tsx與setup語法糖,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-09-09
  • vue3點(diǎn)擊按鈕下載文件功能的代碼實(shí)現(xiàn)

    vue3點(diǎn)擊按鈕下載文件功能的代碼實(shí)現(xiàn)

    在寫vue項目時,有個需求是點(diǎn)擊表格中某一行的下載按鈕,然后開始下載這一行對應(yīng)的文件,所以本文小編給大家介紹了使用vue3實(shí)現(xiàn)點(diǎn)擊按鈕下載文件功能,文中有詳細(xì)的代碼示例供大家參考,需要的朋友可以參考下
    2024-01-01
  • Vue extends 屬性的用法示例詳解

    Vue extends 屬性的用法示例詳解

    這篇文章主要為大家介紹了Vue extends 屬性的用法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • vue 解決報錯問題小結(jié)

    vue 解決報錯問題小結(jié)

    最近入門vue,用字節(jié)跳動的arco初始化一個項目的時候報錯自己解決后沒來的及截圖,從別人那拷貝個網(wǎng)圖把,是一樣的報錯,本文給大家分享vue 解決報錯問題小結(jié),感興趣的朋友一起看看吧
    2023-09-09
  • vue通過接口直接下載java生成好的Excel表格案例

    vue通過接口直接下載java生成好的Excel表格案例

    這篇文章主要介紹了vue通過接口直接下載java生成好的Excel表格案例
    2020-10-10

最新評論