a-table(AntDesign Vue)实现表格行上下拖动排序
参考链接:
-
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
<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);// 更改顺序接口 }, }; }, }
学而不思则罔,思而不学则殆!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
2022-12-07 设置图片和文字垂直居中