https://blog.youkuaiyun.com/weixin_46527264/article/details/111693851 参考这个
https://www.cnblogs.com/jin-zhe/p/10181852.html
https://www.cnblogs.com/e0yu/p/11163924.html
引入三方插件 sortable.js
1.引入sortable.js的包:
npm install sortablejs --save
2. 引用el-table 中 导入
import Sortable from 'sortablejs'
3.mounted(){
this.rowDrop()
this.columnDrop()
}
4.
//行拖拽 //tableData 表格数据
rowDrop() {
const tbody = document.querySelector('.el-table__body-wrapper tbody')
const _this = this
Sortable.create(tbody, {
onEnd({ newIndex, oldIndex }) {
const currRow = _this.tableData.splice(oldIndex, 1)[0]
_this.tableData.splice(newIndex, 0, currRow)
}
})
},
//列拖拽 dropCol 表格定义的header
columnDrop() {
const wrapperTr = document.querySelector('.el-table__header-wrapper tr')
this.sortable = Sortable.create(wrapperTr, {
animation: 180,
delay: 0,
onEnd: evt => {
const oldItem = this.dropCol[evt.oldIndex]
this.dropCol.splice(evt.oldIndex, 1)
this.dropCol.splice(evt.newIndex, 0, oldItem)
}
})
}
本文介绍如何利用sortable.js插件为Element UI的el-table组件添加行和列的拖拽排序功能。通过npm安装sortable.js并将其集成到项目中,可以实现在表格内的数据行和列的自由拖拽调整顺序,适用于需要灵活排序的场景。
1万+

被折叠的 条评论
为什么被折叠?



