element ui + sortablejs实现表格的行列拖拽
<template>
<div class="container">
<el-table :data="tableData" border row-key="id">
<el-table-column
align="center"
v-for="(item, index) in col"
:key="`col_${index}`"
:prop="dropCol[index].prop"
:label="item.label"
></el-table-column>
</el-table>
</div>
</template> <script>
import Sortable from "sortablejs";
export default {
data() {
return {
col: [
{
label: "日期",
prop: "date"
},
{
label: "姓名",
prop: "name"
},
{
label: "地址",
prop: "address"
}
],
dropCol: [
{
label: "日期",
prop: "date"
},
{
label: "姓名",
prop: "name"
},
{
label: "地址",
prop: "address"
}
],
tableData: [
{
id: 1,
date: "2016-05-02",
name: "王小虎1",
address: "上海市普陀区金沙江路 100 弄"
},
{
id: 2,
date: "2016-05-04",
name: "王小虎2",
address: "上海市普陀区金沙江路 200 弄"
},
{
id: 3,
date: "2016-05-01",
name: "王小虎3",
address: "上海市普陀区金沙江路 300 弄"
},
{
id: 4,
date: "2016-05-03",
name: "王小虎4",
address: "上海市普陀区金沙江路 400 弄"
}
]
};
},
components: { },
mounted() {
// 阻止默认行为
document.body.ondrop = function(event) {
event.preventDefault();
event.stopPropagation();
};
this.rowDrop();
this.columnDrop();
},
methods: {
//行拖拽
rowDrop() {
const tbody = document.querySelector(".el-table__body-wrapper tbody");
const _this = this;
Sortable.create(tbody, {
onEnd({ newIndex, oldIndex }) {
const currRow = _this.tableData.splice(oldIndex, 1)[0];
_this.tableData.splice(newIndex, 0, currRow);
}
});
},
//列拖拽
columnDrop() {
const wrapperTr = document.querySelector(".el-table__header-wrapper tr");
this.sortable = Sortable.create(wrapperTr, {
animation: 180,
delay: 0,
filter: ".cannotDrag",
onEnd: evt => {
const oldItem = this.dropCol[evt.oldIndex];
this.dropCol.splice(evt.oldIndex, 1);
this.dropCol.splice(evt.newIndex, 0, oldItem);
}
});
}
}
};
</script> <style scoped lang="scss"> </style>
注意: 当一个页面有多个表格时候 选择器 换成 querySelectorAll 做对应的判断处理即可;更多属性请遵照官网api:http://www.sortablejs.com/options.html,自己写的表格或者ul需要拖拽的话itme的样式使用display:inline-block;
element ui + sortablejs实现表格的行列拖拽的更多相关文章
- vue2.0 + Element UI + axios实现表格分页
注:本文分页组件用原生 html + css 实现,element-ui里有专门的分页组件可以不用自己写,详情见另一篇博客:https://www.cnblogs.com/zdd2017/p/1115 ...
- Blend Grid行列拖拽控制宽高
原文:Blend Grid行列拖拽控制宽高 看效果 <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width=&qu ...
- element ui table(表格)点击一行展开
element ui是一个非常不错的vue的UI框架,element对table进行了封装,简化了vue对表格的渲染. element ui表格中有一个功能是展开行,在2.0版本官网例子中,只可以点击 ...
- el-table实现行列拖拽
element ui 表格没有自带的拖拽排序的功能,只能借助第三方插件Sortablejs来实现. 实现步骤: 安装Sortable.js npm install sortablejs --save ...
- 利用插件(jQuery-ui.js)实现表格行的拖拽排序
template 模板(html) 首先要引入jQuery-ui.js的文件.import './../../scripts/base/jquery/jquery-ui.min.js';<tab ...
- jQuery UI =>jquery-ui.js中sortable方法拖拽对象位置偏移问题
今天要处理sortable方法处理的对象,拖拽的时候,位置偏移的问题. 按理应该是鼠标在哪,对象就跟着在哪的 百度了一下问题,http://blog.csdn.net/samed/article/de ...
- Jquery easyui treegrid实现树形表格的行拖拽
前几天修改了系统的一个功能——实现树形列列表的行拖拽,以达到排序的目的.现在基本上功能实现,现做一个简单的总结. 1.拿到这个直接网上搜,有好多,但是看了后都觉得不是太复杂就是些不是特别想看的例子,自 ...
- Element ui 中的表格数据格式转换
- 原生js实现 table表格列宽拖拽
查看效果 <!DOCTYPE html> <html> <head> <meta charset="gbk"> <title& ...
随机推荐
- ArcGIS 生成要素轮廓线掩膜
先说效果: 生成轮廓之前:
- ThreadLocal如何回收value,什么时候回收?(学习笔记)
1)ThreadLocal如何回收value,什么时候回收?从ThreadLocal中的内部类分析:① static class ThreadLocalMap { /** * The entries ...
- Linux下g++编译thread出错的的解决方法
错误如下图所示: 因为thread是C++11新加入的特性,所以我们在用g++编译的时候不能直接用,需要在g++后面加上 -std=c++0x -pthread 如果是gcc编译多线程的话则应该要用 ...
- Anniversary party(hdu1520)(poj2342)题解
原题地址:http://poj.org/problem?id=2342 题目大意: 上司和下属不能同时参加派对,求参加派对的最大活跃值. 关系满足一棵树,每个人都有自己的活跃值(-128~127) 求 ...
- A&G¥C015
A&G¥C015 A A+...+B Problem 正常A+B我还是会的,但是又加了个省略号就不会了/kk B Evilator 不会 C Nuske vs Phantom Thnook 以 ...
- 【题解】洛谷 P1449 后缀表达式
目录 题目 思路 \(Code\) 题目 P1449 后缀表达式 思路 栈.题目说的不是很清楚,没说包含什么操作.除法用整数除法就行. 先string读入字符串,然后从前往后看如果是个数字就入栈,如果 ...
- JAVA基础--环境搭建
概况 系统:win10 企业版 IDE:Eclipse 4.7.3 JDK:jdk1.8.0_171 数据库:SQLServer2012 Oracle,未安装MySQL 安装 JDK与开发工具(Ecl ...
- LOJ3097 SNOI2019 通信 题解
题目链接 费用流,当建边需要依靠位置和权值两个偏序关系时,可以用cdq分治优化建边. 代码: #include<bits/stdc++.h> using namespace std; #d ...
- 04-树6 Complete Binary Search Tree (30 分)
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...
- win10系统2分钟睡眠
https://blog.csdn.net/widenstage/article/details/78982722 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe ...