sortablejs插件在el-table中的运用 概述需求 有一个Table表格,由于数据是根据自增的ID进行排序显示的,有时了调整顺序会在数据库中直接操作数据表,来达到调整数据顺序的目的,因为为了实现在页面实现较为简单的拖拽排序 最后sortablejs插件可以满足需求并可以快捷的实现功能。 参看资料: 官网:http://www.sortablejs.com/ 中文文档:https://www.itxst.com/sortablejs/neuinffi.html 1、安装sortablejs 插件 首先引入依赖,并重启项目 npm install sortablejs --save 2、实现效果 首先看下实现的效果如下: 1、这是原来的顺序:[1, 2, 3, 4] 2、通过鼠标拖拉即可改变位置 : [4, 3, 1, 2] 3、编写vue页面(文末有完整页面) 3.1、在需要编写排序的页面引入sortablejs依赖 import Sortable from 'sortablejs';
Github:https://github.com/SortableJS/vue.draggable.next,完整代码如下: <draggable v-model="myArray" #item,内容区域的插槽,参数{element,index} #header,#footer,顶部和底部不触发拖动的区域元素 各种方法 完整参数说明:https://github.com/SortableJS
<el-table-column prop="ID" label="座号" sortable> </el-table> 但是,element官方组件并不支持拖拽排序,我在这里引入sortablejs 实现拖拽排序的功能 sortablejs GitHub地址 //sortablejs GitHub地址 https://github.com/SortableJS/Sortable#readme //安装 sortable.js Install with NPM: $ npm install sortablejs --save //在组件内引入 import Sortable from 'sortablejs
说到拖拽工具库,非大名鼎鼎的的 Sortablejs 莫属。它是前端领域比较知名的,且功能强大的工具。但我们直接使用Sortablejs的情况很少,一般都是使用基于它的封装工具。 关于 VueDraggablePlus VueDraggablePlus 是一个专为 Vue 打造的拖拽排序模块,基于 Sortablejs 封装,支持 Vue3 或 Vue 2.7+。 —Vue.js 作者尤雨溪 ps:按照官方的说法,由于 Sortablejs 的 vue3 组件一直没有更新,已经跟 vue3 严重脱节,所以诞生了这个VueDraggablePlus项目。 在任何元素上使用拖拽列表 在 Sortablejs 官方以往的 Vue 组件中,都是通过使用组件作为列表的直接子元素来实现拖拽列表。 它可以让你在任何元素上使用拖拽列表,我们可以使用指定元素的选择器,来获取到列表根元素,然后将列表根元素作为 Sortablejs 的 container。这样我们就不用自己再包一层啦。
基于vue+sortable.js实现表格行拖拽 实践环境 sortablejs@1.13.0 vue@2.6.11 element-ui@2.13.2 安装sortable.js拖拽库 npm install sortablejs 代码示例 <template>
下载依赖 npm i sortablejs @types/sortablejs 添加类名 首先给 el-table 加上类名:class="elTable" <el-table class="elTable " :data="tableData"> 导入sortablejs //导入sortablejs import Sortable from 'sortablejs'; 初始化拖拽实例 const initSort
el-table 的拖拽使用 Sortable.js 官方文档 :https://github.com/SortableJS/Sortable 1. 通过 npm 使用 sortable //安装sortablejs npm install sortablejs --save //引用 sorttablejs import Sortable from 'sortablejs' 2.用法 SorRow() { // 获取表格row的父节点 const tbody = this. template> </el-table-column> </el-table>
Sortablejs 简介 Sortable —是一个JavaScript库,用于在现代浏览器和触摸设备上对拖放列表进行重新排序。无需jQuery。 --save 导入 // Default SortableJS import Sortable from 'sortablejs'; // Core SortableJS (without default plugins) import Sortable from 'sortablejs/modular/sortable.core.esm.js'; // Complete SortableJS (with all plugins) import Sortable from 'sortablejs/modular/sortable.complete.esm.js'; 插件导入 // Cherrypick extra plugins import Sortable, { MultiDrag, Swap } from 'sortablejs'; Sortable.mount(new MultiDrag(
Github链接:https://github.com/SortableJS/Vue.Draggable Github Star:19K Sortable.js Sortable是一个功能强大且易于使用的 Github链接:https://github.com/SortableJS/Sortable Github Star:27.1K dragula dragula是一个轻量级的JavaScript库,用于实现页面元素的拖拽操作
https://github.com/SortableJS/Vue.Draggable 演示 https://sortablejs.github.io/Vue.Draggable/#/simple Vue-Socket.io
保存所有数据每日小结导出:自动生成报告,支持导出 Markdown技术选型框架:Vue 3 + Composition API状态管理:组合式响应式变量本地存储:IndexedDB(使用 idb 库简化操作)拖拽交互:SortableJS moods', { date: today(), type }))}拖拽排序 + 实时保存// 使用 Sortable.js 实现任务拖拽并保存新顺序import Sortable from 'sortablejs'onMounted
": "^1.0.1", "angular-progress-http": "^1.0.0", "angular-safeguard": "^2.0.1", "angular-sortablejs print-js": "^1.0.61", "quill": "^1.3.6", "rxjs": "~6.2.0", "rxjs-compat": "^6.2.2", "sortablejs
scope.row[item.prop]}}
</template> </el-table-column> </el-table> import Sortable from 'sortablejs「github:」 https://github.com/SortableJS/Sortable 「demo地址:」 https://sortablejs.github.io/Sortable/ 5.
「github:」 https://github.com/SortableJS/Sortable 「demo地址:」 https://sortablejs.github.io/Sortable/ 5.
name": "item7","id": 7,"indexid": 9} ] 2、dom原始使用flex布局,拖拽时使用Vue.Draggable插件, 下载地址:https://github.com/SortableJS /Vue.Draggable#start-of-content 演示地址:https://sortablejs.github.io/Vue.Draggable/#/simple 3、一开始左边加载所有的
div :key="tableKey"> <slot />
emitter.emit('refresh',{id:123})//组件B:监听事件emitter.on('refresh',(data)=>{console.log('收到刷新事件',data.id)})4.4sortablejs divv-for="iteminlist":key="item.id">{{item.name}}
具体实例效果(拖拽行) 点击文末左下方阅读原文即可体验 https://coder.itclan.cn/fontend/css/business-col-draw/ 行拖拽的具体实现 这里的拖拽主要借用的是sortablejs 实现的,具体代码如下所示 import Sortable from 'sortablejs'; // 引入sortable // 拖拽方法 dropRow(endHandle) { const /tableComp.vue"; import Sortable from 'sortablejs'; // 表格拖拽 export default { components: { tableComp
:比如编辑,删除,查看详情)3.表格的顶部可操作(ps:展开,排序)4.表格尾部可分页 5.表格可多选(ps:表格带复选框) 多功能的表格组件 安装插件 npm install element-ui sortablejs -S 在项目中我是使用sortablejs实现拖拽的,以及使用elemnt-ui的分页组件实现分页的功能。