sortable中el-table拖拽及點(diǎn)擊箭頭上下移動(dòng)row效果
效果
安裝
npm install sortablejs --save
引入
import Sortable from "sortablejs";
<el-table :data="tableBody" border ref="tableRef" :stripe="true" :key="tableKey" > <el-table-column type="index" label="排序" width="150" key="index" /> <el-table-column prop="category" label="大類(lèi)名稱" key="category"> <template #default="{ row, $index }"> <div class="title">{{ row.category }}</div> <div class="icon"> <el-icon :class="{ active: activeButton === `up-${$index}` }" @click="moveItem($index, 'up')" ><CaretTop /></el-icon> <el-icon :class="{ active: activeButton === `down-${$index}` }" @click="moveItem($index, 'down')" ><CaretBottom /></el-icon> </div> </template> </el-table-column> </el-table> <script setup> const activeButton = ref(); //行拖拽 const rowDrop=()=> { const tbody = tableRef.value?.$el.querySelector( ".el-table__body-wrapper tbody" ); Sortable.create(wrapperTr, { animation: 150, ghostClass: "blue-background-class", onEnd: async (evt: any) => { handleDragEnd(evt); }, }); } const handleDragEnd = async (event: any) => { const { oldIndex, newIndex } = event; if (oldIndex !== newIndex) { const movedItem = tableBody.value.splice(oldIndex, 1)[0]; tableBody.value.splice(newIndex, 0, movedItem); tableKey.value += 1; const url = "./?_m=&_a="; const formData = new FormData(); formData.append("id", globalData.id); formData.append("category", movedItem.category); formData.append("xh", newIndex + 1); const response = await post(url, formData); if (response.code == 0) { ElMessage({ showClose: true, message: "排序成功", type: "success", }); } } }; const moveItem = async (index: any, direction: any) => { const newIndex = direction == "up" ? index - 1 : index + 1; if (newIndex >= 0 && newIndex < tableBody.value.length) { const item = tableBody.value.splice(index, 1)[0]; tableBody.value.splice(newIndex, 0, item); activeButton.value = `${direction}-${index}`; setTimeout(() => (activeButton.value = null), 200); const url = "./?_m=&_a="; const formData = new FormData(); formData.append("id", globalData.id); formData.append("category", item.category); formData.append("xh", newIndex + 1); const response = await post(url, formData); if (response.code == 0) { ElMessage({ showClose: true, message: "排序成功", type: "success", }); } } }; </script>
點(diǎn)擊箭頭加顏色
.active { color: #009688; /* 例如,活動(dòng)狀態(tài)的顏色 */ }
到此這篇關(guān)于sortable中el-table拖拽及點(diǎn)擊箭頭上下移動(dòng)row的文章就介紹到這了,更多相關(guān)sortable el-table拖拽內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS實(shí)現(xiàn)來(lái)回出現(xiàn)文字的狀態(tài)欄特效代碼
這篇文章主要介紹了JS實(shí)現(xiàn)來(lái)回出現(xiàn)文字的狀態(tài)欄特效代碼,針對(duì)文字的定義及狀態(tài)欄的定時(shí)顯示等實(shí)現(xiàn)方法備有詳細(xì)的文字說(shuō)明,需要的朋友可以參考下2015-10-10json_decode 索引為數(shù)字時(shí)自動(dòng)排序問(wèn)題解決方法
這篇文章主要介紹了使用son_encode 給前端返回?cái)?shù)據(jù),結(jié)果順序不對(duì),經(jīng)debug調(diào)試,發(fā)現(xiàn)是json_encode 函數(shù)的問(wèn)題,變成 " " + 數(shù)字即可,需要的朋友可以參考下2020-03-03js中symbol類(lèi)型以及symbol的三大應(yīng)用場(chǎng)景詳解
Symbol是ES6新推出的一種基本類(lèi)型,它表示獨(dú)一無(wú)二的值,它可以接受一個(gè)字符串作為參數(shù),帶有相同參數(shù)的兩個(gè)Symbol值不相等,這個(gè)參數(shù)只是表示Symbol值的描述而已,下面這篇文章主要給大家介紹了關(guān)于js中symbol類(lèi)型以及symbol的三大應(yīng)用場(chǎng)景,需要的朋友可以參考下2022-09-09ImageZoom 圖片放大鏡效果(多功能擴(kuò)展篇)
上一篇ImageZoom已經(jīng)對(duì)圖片放大效果做了詳細(xì)的分析,這次在ImageZoom的基礎(chǔ)上進(jìn)行擴(kuò)展,實(shí)現(xiàn)更多的效果。2010-04-04Javascript如何實(shí)現(xiàn)雙指控制圖片功能
這篇文章主要介紹了Javascript如何實(shí)現(xiàn)雙指控制圖片功能,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02JS實(shí)現(xiàn)完全語(yǔ)義化的網(wǎng)頁(yè)選項(xiàng)卡效果代碼
這篇文章主要介紹了JS實(shí)現(xiàn)完全語(yǔ)義化的網(wǎng)頁(yè)選項(xiàng)卡效果代碼,可實(shí)現(xiàn)基于鼠標(biāo)滑過(guò)及點(diǎn)擊的選項(xiàng)卡切換效果,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-09-09JavaScript算法題之如何將一個(gè)數(shù)組旋轉(zhuǎn)k步
這篇文章主要給大家介紹了關(guān)于JavaScript算法題之如何將一個(gè)數(shù)組旋轉(zhuǎn)k步的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2022-03-03