a-table(AntDesign Vue)实现表格行上下拖动排序

参考链接:

  1. https://blog.csdn.net/song_de/article/details/125218350

  2. https://blog.csdn.net/m0_61342618/article/details/132556739?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-1-132556739-blog-125218350.235v39pc_relevant_3m_sort_dl_base2&spm=1001.2101.3001.4242.2&utm_relevant_index=4

  3. https://zhuanlan.zhihu.com/p/595184666?utm_id=0

<a-table
class="api-ant-table"
rowKey="itemId"
:scroll="{ x: true, y: true }"
:columns="columns"
:data-source="dicitemList"
:pagination="false"
:row-selection="{
selectedRowKeys: selectedRowKeys,
onChange: onSelectChange,
}"
:loading="loading"
:customRow="customRow"
>
<a-table/>
data() {
return {
dicitemList: [],
sourceObj: null, // 原对象
targetObj: null, // 目标对象
}
},
methods: {
customRow(record, index) {
console.log(record, index);
return {
style: {
cursor: "move",
},
// 鼠标移入
onMouseenter: (event) => {
// 兼容IE
var ev = event || window.event;
ev.target.draggable = true;
},
// 开始拖拽
onDragstart: (event) => {
// 兼容IE
var ev = event || window.event;
// 阻止冒泡
ev.stopPropagation();
// 得到源目标数据
this.sourceObj = record;
},
// 拖动元素经过的元素
onDragover: (event) => {
// 兼容 IE
var ev = event || window.event;
// 阻止默认行为
ev.preventDefault();
},
// 鼠标松开
onDrop: (event) => {
// 兼容IE
var ev = event || window.event;
// 阻止冒泡
ev.stopPropagation();
// 得到目标数据
this.targetObj = record;
console.log(this.sourceObj, this.targetObj);
const tempDta = this.dicitemList;
tempDta[this.targetObj.weight] = this.sourceObj;
tempDta[this.sourceObj.weight] = this.targetObj;
let weightList = [];
tempDta.forEach((item, index) => {
item.weight = index;
weightList.push({
id: item.id,
weight: index,
});
});
// this.handleWeightModify(weightList);// 更改顺序接口
},
};
},
}
posted @   Felix_Openmind  阅读(2068)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
历史上的今天:
2022-12-07 设置图片和文字垂直居中
*{cursor: url(https://files-cdn.cnblogs.com/files/morango/fish-cursor.ico),auto;}
点击右上角即可分享
微信分享提示