日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用sortablejs实现表格拖拽排序

發(fā)布時間:2024/5/14 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用sortablejs实现表格拖拽排序 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.


拖動紅色區(qū)域可以實現(xiàn)行排序

1.下載

npm install sortablejs --save

2.引用

import Sortable from "sortablejs";

3.el-table使用拖拽

<el-table:data="columnTableData":header-cell-style="{background:'#F5F7FA'}"style="width: 100%"size="small"row-key="id"ref="columnTable"><el-table-column label="拖動" width="50px"><template slot-scope="scope"><div class="drag"><i class="fa fa-arrows" aria-hidden="true"></i></div></template></el-table-column><el-table-column prop="title" label="列名"></el-table-column><el-table-column prop="field" label="字段"></el-table-column> </el-table>

4.拖拽后改變數(shù)據(jù)

created() {this.$nextTick(() => {this.columnDataDrag();});},columnDataDrag() {if (this.$refs.columnTable) {const el1 = this.$refs.columnTable.$el.querySelectorAll(".el-table__body-wrapper > table > tbody ")[0];Sortable.create(el1, {disabled: false, // 拖拽不可用? false 啟用ghostClass: "sortable-ghost", //拖拽樣式animation: 150, // 拖拽延時,效果更好看handle: ".drag", // 設置拖拽點onEnd: e => {// 拖拽結束時的觸發(fā)let arr = this.columnTableData; // 獲取表數(shù)據(jù)arr.splice(e.newIndex, 0, arr.splice(e.oldIndex, 1)[0]); // 數(shù)據(jù)處理,獲取最新的表格數(shù)據(jù)this.$nextTick(function() {this.columnTableData = arr;// console.log("columnTableData:", this.columnTableData);});}});}}

總結

以上是生活随笔為你收集整理的使用sortablejs实现表格拖拽排序的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。