Vue使用vxe-table實現(xiàn)Excel單元格數(shù)據(jù)填充功能
在數(shù)據(jù)編輯場景中,用戶經(jīng)常需要將某個單元格或區(qū)域的內(nèi)容快速復制到下方單元格。vxe-table 提供了類 Excel 的填充功能:選取區(qū)域后按下 Ctrl + D 鍵,即可將選中區(qū)域最上方單元格的值依次填充到下方單元格。
本文將通過完整示例,講解如何通過 areaConfig.isFillByCopy 配置項啟用該功能,并結(jié)合區(qū)域選取、編輯模式等打造高效的數(shù)據(jù)錄入體驗。
相關(guān)配置
| 配置路徑 | 值示例 | 作用 |
|---|---|---|
| mouseConfig.area | true | 開啟單元格區(qū)域選取功能(鼠標框選) |
| mouseConfig.extension | true | 開啟區(qū)域擴展按鈕(選中區(qū)域右下角的小方塊,可拖拽擴大區(qū)域) |
| vareaConfig.multiple | true | 允許多個不連續(xù)區(qū)域選?。ò醋?Ctrl 多選) |
| areaConfig.isFillByCopy | true | 啟用向下填充快捷鍵:Ctrl + D |
| keyboardConfig.isClip | true | 開啟剪貼板快捷鍵(復制 / 粘貼) |
| editConfig | { mode: ‘cell’, trigger: ‘dblclick’ } | 設(shè)為單元格編輯模式,雙擊進入編輯 |
最關(guān)鍵的一點:areaConfig.isFillByCopy 必須設(shè)置為 true,否則 Ctrl + D 將無效。
效果

代碼
<template>
<div>
<vxe-grid v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script setup>
import { reactive } from 'vue'
const gEditRender = reactive({
name: 'VxeSelect',
props: {},
options: [
{ label: 'Develop', value: '1' },
{ label: 'Test', value: '2' },
{ label: 'Designer', value: '3' },
{ label: 'PM', value: '4' }
]
})
const hEditRender = reactive({
name: 'VxeSelect',
props: {
multiple: true
},
options: [
{ label: 'Develop', value: '1' },
{ label: 'Test', value: '2' },
{ label: 'Designer', value: '3' },
{ label: 'PM', value: '4' }
]
})
const gridOptions = reactive({
border: true,
height: 500,
showOverflow: true,
columnConfig: {
resizable: true
},
editConfig: {
mode: 'cell', // 單元格編輯模式
trigger: 'dblclick' // 雙擊單元格激活編輯狀態(tài)
},
mouseConfig: {
area: true, // 是否開啟區(qū)域選取
extension: true // 是否開啟區(qū)域擴展選取功能,開啟后可以通過鼠標左鍵按住區(qū)域內(nèi)右下角擴展按鈕,將區(qū)域橫向或縱向擴大
},
areaConfig: {
multiple: true, // 是否啟用多區(qū)域選取功能
isFillByCopy: true // 是否啟用選中復制填充功能,自動把上面的單元格內(nèi)容填到下面(按 ctrl + D 鍵觸發(fā))
},
keyboardConfig: {
arrowCursorLock: true, // 方向鍵光標鎖,開啟后處于非聚焦式編輯狀態(tài),將支持在編輯狀態(tài)中通過方向鍵切換單元格。(切換為聚焦編輯狀態(tài),可以按 F2 鍵或者鼠標左鍵點擊輸入框,就可以用方向鍵左右移動輸入框的光標)
isAll: true, // 是否啟用快捷鍵全選
isClip: true, // 是否開啟復制粘貼
isArrow: true, // 是否開啟方向鍵功能
isShift: true, // 是否開啟同時按住方向鍵以活動區(qū)域為起始,向指定方向擴展單元格區(qū)域
isTab: true, // 是否開啟 Tab 鍵功能
isEnter: true, // 是否開啟回車鍵功能
isEdit: true, // 是否開啟任意鍵進入編輯(功能鍵除外)
isDel: true, // 是否開啟刪除鍵功能
isEsc: true, // 是否開啟Esc鍵關(guān)閉編輯功能
isFNR: true // 是否開啟查找與替換
},
columns: [
{ type: 'seq', width: 60 },
{ field: 'a', title: 'A', editRender: { name: 'VxeInput' } },
{ field: 'b', title: 'B', editRender: { name: 'VxeInput' } },
{ field: 'c', title: 'C', editRender: { name: 'VxeInput' } },
{ field: 'd', title: 'D', editRender: { name: 'VxeInput' } },
{ field: 'e', title: 'E', editRender: { name: 'VxeInput' } },
{ field: 'f', title: 'F', editRender: { name: 'VxeInput' } },
{ field: 'g', title: 'G單選', editRender: gEditRender },
{ field: 'h', title: 'H多選', minWidth: 200, editRender: hEditRender }
],
data: [
{ id: 10001, a: 'Test1', b: 'Develop', c: 'Man', d: '23', e: '28', f: '', g: '', h: [] },
{ id: 10002, a: 'Test2', b: 'Test', c: 'Women', d: '23', e: '22', f: '', g: '', h: [] },
{ id: 10003, a: 'Test3', b: 'PM', c: 'Man', d: '23', e: '32', f: '', g: '4', h: ['3', '4'] },
{ id: 10004, a: 'Test4', b: 'Designer', c: 'Women', d: '456', e: '24', f: '', g: '2', h: ['2', '3', '4'] },
{ id: 10005, a: 'Test5', b: 'Designer', c: 'Women', d: '23', e: '42', f: '', g: '1', h: ['1', '2'] },
{ id: 10006, a: 'Test6', b: 'Designer', c: 'Man', d: '23', e: '38', f: '', g: '3', h: [] },
{ id: 10007, a: 'Test7', b: 'Test', c: 'Women', d: '100', e: '24', f: '', g: '', h: [] },
{ id: 10008, a: 'Test8', b: 'PM', c: 'Man', d: '345', e: '34', f: '', g: '', h: [] },
{ id: 10009, a: 'Test9', b: 'Designer', c: 'Man', d: '67', e: '52', f: '', g: '', h: [] },
{ id: 10010, a: 'Test10', b: 'Test', c: 'Women', d: '23', e: '44', f: '', g: '', h: [] }
]
})
</script>說明
- 選取區(qū)域
- 鼠標左鍵按住并拖拽,可以框選一個矩形區(qū)域(連續(xù)單元格)。
- 按住 Ctrl 鍵可以同時選中多個不連續(xù)的區(qū)域。
- 向下填充(Ctrl + D)
- 選中一個多行區(qū)域(例如 A2:C5),按下 Ctrl + D。
- 系統(tǒng)會將選中區(qū)域最上方那一行的值,復制到該區(qū)域下方的每一行中。
- 如果選中的區(qū)域只有一列,則會把頂部單元格的值向下填充至該列剩余行。
- 支持編輯器類型
- 普通輸入框(VxeInput)→ 值直接復制。
- 單選下拉(VxeSelect)→ 選中的值(value)被復制。
- 多選下拉(multiple: true)→ 數(shù)組形式的選中值被完整復制。
- 區(qū)域擴展按鈕
- 當選中一個區(qū)域后,右下角會出現(xiàn)一個小方塊,鼠標按住并拖拽可以橫向或縱向擴展選區(qū),擴展后區(qū)域內(nèi)單元格內(nèi)容會自動填充(類似 Excel 的填充柄)。
以上就是Vue使用vxe-table實現(xiàn)Excel單元格數(shù)據(jù)填充功能的詳細內(nèi)容,更多關(guān)于Vue vxe-table Excel單元格數(shù)據(jù)填充的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
daisyUI解決TailwindCSS堆砌class問題詳解
這篇文章主要為大家介紹了daisyUI解決TailwindCSS堆砌class問題詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-07-07
vue+element-ui+ajax實現(xiàn)一個表格的實例
下面小編就為大家分享一篇vue+element-ui+ajax實現(xiàn)一個表格的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03
Vue報錯:TypeError:?Cannot?create?property?‘xxxx‘?on的解決
這篇文章主要介紹了Vue報錯:TypeError:?Cannot?create?property?‘xxxx‘?on的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06
vue實現(xiàn)手機號碼的校驗實例代碼(防抖函數(shù)的應(yīng)用場景)
這篇文章主要給大家介紹了關(guān)于vue實現(xiàn)手機號碼的校驗的相關(guān)資料,主要是防抖函數(shù)的應(yīng)用場景,文中通過示例代碼介紹的非常詳細,對大家學習或者使用vue具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-09-09

