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="請輸入" size="small" /> <div style="margin-top: 5px; display: flex; justify-content: space-between;"> <el-button size="small" type="primary" @click="searchItem(item)">查詢</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: '名稱', prop: 'name', input: '', visible: false}, {label: '類型', prop: 'type', input: '', visible: false}, {label: '價格', prop: 'price', input: '', visible: false}, ]) onMounted(() => { // 頁面加載完成執(zhí)行拖拽函數(shù) rowDrop() columnDrop() }) // 列查詢 const searchItem = (item: any) => { item.visible = false console.log(item); } // 列查詢重置 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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
VUE element-ui 寫個復(fù)用Table組件的示例代碼
本篇文章主要介紹了VUE element-ui 寫個復(fù)用Table組件的示例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11Vue.js中的計(jì)算屬性、監(jiān)視屬性與生命周期詳解
最近在學(xué)習(xí)vue,學(xué)習(xí)中遇到了一些感覺挺重要的知識點(diǎn),感覺有必要整理下來,這篇文章主要給大家介紹了關(guān)于Vue.js中計(jì)算屬性、監(jiān)視屬性與生命周期的相關(guān)資料,需要的朋友可以參考下2021-06-06element-ui table行點(diǎn)擊獲取行索引(index)并利用索引更換行順序
這篇文章主要介紹了element-ui table行點(diǎn)擊獲取行索引(index)并利用索引更換行順序,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02VUEJS 2.0 子組件訪問/調(diào)用父組件的實(shí)例
下面小編就為大家分享一篇VUEJS 2.0 子組件訪問/調(diào)用父組件的實(shí)例。具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02element的el-tree多選樹(復(fù)選框)父子節(jié)點(diǎn)關(guān)聯(lián)不關(guān)聯(lián)
最近想要實(shí)現(xiàn)多選框關(guān)聯(lián)的功能,但是卻出現(xiàn)了element的el-tree多選樹(復(fù)選框)父子節(jié)點(diǎn)關(guān)聯(lián)不關(guān)聯(lián)的問題,本文就來介紹一下解決方法,一起來了解一下2021-05-05前端vue+express實(shí)現(xiàn)文件的上傳下載示例
本文主要介紹了前端vue+express實(shí)現(xiàn)文件的上傳下載示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12