Sortable实现table拖拽功能
2019-04-30 11:54
225 查看
1.安装插件
[code]npm install sortablejs --save
2.使用插件
[code]<template> <el-table :data="tableData" id="table" row-key="id" border style="width: 300px;"> <el-table-column type="index" fixed width="50" label="序号"></el-table-column> <el-table-column prop="name" label="姓名" width="180"></el-table-column> <el-table-column label="操作" width="70"> <template slot-scope="scope"> <i style="font-size: 24px; color: blue;" class="el-icon-menu"></i> </template> </el-table-column> </el-table> </template> <script> import Sortable from 'sortablejs' export default{ name: 'tableEle', data () { return { tableData: [ { name: '张三', id: 1 }, { name: '李四', id: 2 }, { name: '王五', id: 3 }, { name: '赵六', id: 4 } ] } }, created () { }, mounted () { // 调用拖拽方法 this.rowDrop() }, methods: { // 行拖拽 rowDrop () { const tbody = document.querySelector('#table tbody') const _this = this Sortable.create(tbody, { onEnd ({ newIndex, oldIndex }) { const currRow = _this.tableData.splice(oldIndex, 1)[0] _this.tableData.splice(newIndex, 0, currRow) } }) } } } </script> <style lang="less" scoped> </style>
注意:1.一定要指定行的唯一标识 row-key="id"
相关文章推荐
- vue2.0使用Sortable.js实现的拖拽功能示例
- vuejs2.0使用Sortable.js实现的拖拽功能
- vue2.0使用Sortable.js实现的拖拽功能
- jquery sortable实现table拖拽排序,更新时只更新受影响的行
- vuejs2.0使用Sortable.js实现的拖拽功能
- vuejs2.0使用Sortable.js实现的拖拽功能
- jquery ui 实现table的sortable功能以及过滤记录功能
- vue2.0使用Sortable.js实现的拖拽功能
- vue2.0使用Sortable.js实现的拖拽功能
- vuejs2.0使用Sortable.js实现的拖拽功能
- Android一步一步带你实现RecyclerView的拖拽和侧滑删除功能
- ASP.NET中使用MultiView和View以及Menu实现Tablecontrol的功能
- html5指南--3.拖拽功能的实现
- JS实现页面table鼠标移动改变tr行颜色,单击tr选中复选框功能
- php接口实现拖拽排序功能
- HTML中点击TABLE列头实现排序功能
- Qt Graphics入门小例以及实现场景中相关项拖拽功能总结.
- 仿QQ好友 TableView 点击展开 收缩功能实现
- javascript实现的具有EXCEL功能的table
- iOS实现tableView下拉搜索功能