vue3 elementPlus 表格實(shí)現(xiàn)行列拖拽及列檢索功能(完整代碼)
vue3 elementPlus 表格實(shí)現(xiàn)行列拖拽及列檢索功能
1、安裝vuedraggable
npm i -S vuedraggable@next
2、完整代碼
<template> <div class='container'> <div class="dragbox"> <el-table row-key="id" :data="tableData" :border="true"> <el-table-column v-for="item in columnList" :key="item.prop" :prop="item.prop" :label="item.label" sortable > <template #header> {{item.label}} <el-popover :visible="item.visible" placement="bottom" :width="200" trigger="click" > <template #reference> <el-button :type="item.input===''?'info':'primary'" link :icon="Search" @click.stop="item.visible = !item.visible"></el-button> </template> <div> <el-input v-model="item.input" placeholder="請(qǐng)輸入" size="small" /> <div style="margin-top: 5px; display: flex; justify-content: space-between;"> <el-button size="small" type="primary" @click="searchItem(item)">查詢(xún)</el-button> <el-button size="small" @click="resetItem(item)">重置</el-button> </div> </div> </el-popover> </template> </el-table-column> </el-table> </div> </div> </template> <script setup lang='ts'> import { Search } from '@element-plus/icons-vue' import Sortable from "sortablejs" import { ref } from 'vue' const tableData = ref([ {id: 1, name: '紙巾', type: '百貨', price: 30}, {id: 2, name: '抽紙', type: '百貨', price: 18}, {id: 3, name: '水杯', type: '百貨', price: 50}, ]) const columnList = ref([ {label: '名稱(chēng)', prop: 'name', input: '', visible: false}, {label: '類(lèi)型', prop: 'type', input: '', visible: false}, {label: '價(jià)格', prop: 'price', input: '', visible: false}, ]) onMounted(() => { // 頁(yè)面加載完成執(zhí)行拖拽函數(shù) rowDrop() columnDrop() }) // 列查詢(xún) const searchItem = (item: any) => { item.visible = false console.log(item); } // 列查詢(xún)重置 const resetItem = (item: any) => { item.visible = false item.input = '' console.log(item); } // 行拖拽 const rowDrop = () => { const tbody = document.querySelector('.dragbox .el-table__body-wrapper tbody'); Sortable.create(tbody, { draggable: ".dragbox .el-table__row", onEnd(evt: any) { const currRow = tableData.value.splice(evt.oldIndex, 1)[0]; tableData.value.splice(evt.newIndex, 0, currRow); console.log(tableData.value); } }); } // 列拖拽 const columnDrop = () => { const tr = document.querySelector('.dragbox .el-table__header-wrapper tr'); Sortable.create(tr, { animation: 150, delay: 0, onEnd: (evt: any) => { const oldItem = columnList.value[evt.oldIndex]; columnList.value.splice(evt.oldIndex, 1); columnList.value.splice(evt.newIndex, 0, oldItem); console.log(columnList.value); } }); } </script> <style lang='scss' scoped> .container { height: 100vh; .dragbox { height: 100%; } } </style>
到此這篇關(guān)于vue3 elementPlus 表格實(shí)現(xiàn)行列拖拽及列檢索功能的文章就介紹到這了,更多相關(guān)vue3 elementPlus表格行列拖拽內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
VUE element-ui 寫(xiě)個(gè)復(fù)用Table組件的示例代碼
本篇文章主要介紹了VUE element-ui 寫(xiě)個(gè)復(fù)用Table組件的示例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11vue儲(chǔ)存storage時(shí)含有布爾值的解決方案
這篇文章主要介紹了vue儲(chǔ)存storage時(shí)含有布爾值的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06Vue.js中的計(jì)算屬性、監(jiān)視屬性與生命周期詳解
最近在學(xué)習(xí)vue,學(xué)習(xí)中遇到了一些感覺(jué)挺重要的知識(shí)點(diǎn),感覺(jué)有必要整理下來(lái),這篇文章主要給大家介紹了關(guān)于Vue.js中計(jì)算屬性、監(jiān)視屬性與生命周期的相關(guān)資料,需要的朋友可以參考下2021-06-06element-ui table行點(diǎn)擊獲取行索引(index)并利用索引更換行順序
這篇文章主要介紹了element-ui table行點(diǎn)擊獲取行索引(index)并利用索引更換行順序,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02VUEJS 2.0 子組件訪(fǎng)問(wèn)/調(diào)用父組件的實(shí)例
下面小編就為大家分享一篇VUEJS 2.0 子組件訪(fǎng)問(wèn)/調(diào)用父組件的實(shí)例。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-02-02Vue頁(yè)面反復(fù)刷新的常見(jiàn)問(wèn)題及解決方案
Vue.js 是一個(gè)流行的前端框架,旨在通過(guò)其響應(yīng)式的數(shù)據(jù)綁定和組件化的開(kāi)發(fā)模式簡(jiǎn)化開(kāi)發(fā),然而,在開(kāi)發(fā) Vue.js 應(yīng)用時(shí),頁(yè)面反復(fù)刷新的問(wèn)題可能會(huì)對(duì)用戶(hù)體驗(yàn)和開(kāi)發(fā)效率產(chǎn)生負(fù)面影響,本文將深入探討 Vue 頁(yè)面反復(fù)刷新的常見(jiàn)原因,并提供詳細(xì)的解決方案2024-09-09element的el-tree多選樹(shù)(復(fù)選框)父子節(jié)點(diǎn)關(guān)聯(lián)不關(guān)聯(lián)
最近想要實(shí)現(xiàn)多選框關(guān)聯(lián)的功能,但是卻出現(xiàn)了element的el-tree多選樹(shù)(復(fù)選框)父子節(jié)點(diǎn)關(guān)聯(lián)不關(guān)聯(lián)的問(wèn)題,本文就來(lái)介紹一下解決方法,一起來(lái)了解一下2021-05-05前端vue+express實(shí)現(xiàn)文件的上傳下載示例
本文主要介紹了前端vue+express實(shí)現(xiàn)文件的上傳下載示例,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12