开发指南101-拖动排序

平台上实现拖动排序的标准方案如下:

依托组件:

SortableJS

界面元素:

<el-table :data="sortlist" ref="sortTable">

<el-table-column

label="名称"

header-align="center"

align="center"

prop="itemTitleEx"

width="200"

></el-table-column>

--其他列

<el-table-column align="center" label="排序" width="80">

<template slot-scope="scope">

<svg-icon class="drag-handler" icon-class="drag" />

</template>

</el-table-column>

</el-table>

用el-table展示数据,最后一列显示拖动图标。其实拖动图标只是起个提示作用。点击行内即可拖动。

核心处理:

this.oldsortData = this.sortlist.map(v => v.itemID);

this.newsortData = this.oldsortData.slice();

this.sortable = Sortable.create(el, {

animation: 300,

ghostClass: "sortable-ghost",

setData: function(dataTransfer) {

dataTransfer.setData("Text", "");

},

onEnd: evt => {

const tempIndex = this.newsortData.splice(evt.oldIndex, 1)[0];

this.newsortData.splice(evt.newIndex, 0, tempIndex);

this.newsortDataString = this.newsortData.join();

}

});

newsortDataString为拖动后id的序列串,将这个串返回后台接口调整顺序即可

后台接口一般处理方案,就是生成一段批处理sql,就是按newsortDataString的id顺序进行赋值操作,例如第一个赋值001,依次类推。

相关推荐
竹林8181 小时前
RainbowKit 快速集成多链钱包连接:从“连不上”到丝滑切换的踩坑实录
前端·javascript
Ruihong2 小时前
你的 Vue 3 reactive(),VuReact 会编译成什么样的 React?
vue.js·面试
Ruihong2 小时前
你的 Vue 3 ref(),VuReact 会编译成什么样的 React?
vue.js·面试
一 乐2 小时前
酒店预订|基于springboot + vue酒店预订系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·酒店预订系统
嗜好ya2 小时前
解决 Vite 项目中 import.meta.env 变量为 undefined 的问题
前端·javascript·vue.js
心连欣2 小时前
JS算法入门:图解“冒泡排序”,彻底搞懂双重循环的奥义
前端·javascript
浩星3 小时前
「Vue3 + Cesium 最佳实践」完整工程化方案
前端·javascript·vue.js
小李子呢02113 小时前
前端八股Vue(5)---v-if和v-show
前端·javascript·vue.js
YiuChauvin3 小时前
vue2中使用 AntV G6
javascript·vue.js
踩着两条虫4 小时前
目录:VTJ.PRO 在线应用开发平台技术揭秘
vue.js·低代码·ai编程