开发指南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,依次类推。

相关推荐
huangyiyi6666617 小时前
轮询那些事儿
javascript·前端框架·vue·js
CC码码17 小时前
解决前端多标签页通信:BroadcastChannel
前端·javascript·web
墨鸦_Cormorant17 小时前
Vue 概述以及基本使用
前端·javascript·vue.js
鹏多多17 小时前
使用imaskjs实现js表单输入卡号/日期/货币等掩码的教程
前端·javascript·vue.js
艾小码19 小时前
告别页面呆板!这5个DOM操作技巧让你的网站活起来
前端·javascript
正在学习前端的---小方同学21 小时前
vue-easy-tree树状结构
前端·javascript·vue.js
毕业设计制作和分享1 天前
springboot150基于springboot的贸易行业crm系统
java·vue.js·spring boot·后端·毕业设计·mybatis
键盘不能没有CV键1 天前
【图片处理】✈️HTML转图片字体异常处理
前端·javascript·html