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& ...
随机推荐
- 基于 Keil MDK 移植 RT-Thread Nano
后文rtt代表RT-Thread 在官网公众号中,看到rtt发布了rtt nano,这个就很轻量级的rtos内核,把多余的驱动都裁剪了,因此移植工作量小,可以哪来学习一番,体验rtt之美 rtt现在也 ...
- swift的柯里化demo
func baseFunc(go:String, goo:String) -> String { return "hello" + go + goo; } func Curr ...
- 如何开发出优秀的APICloud应用
APICloud定制平台项目实施规范 APICloud应用优化策略Top30 如何开发出运行体验良好.高性能的App 如何开发出客户满意.能够顺利交付的App 1. 引擎或模块问题: 遇到应用层无法解 ...
- LeetCode 490. The Maze
原题链接在这里:https://leetcode.com/problems/the-maze/ 题目: There is a ball in a maze with empty spaces and ...
- 使用grok exporter 做为log 与prometheus 的桥
grok 是一个工具,可以用来解析非结构化的日志文件,可以使其结构化,同时方便查询,grok 被logstash 大量依赖 同时社区也提供了一个prometheus 的exporter 可以方便的进行 ...
- loj#2255. 「SNOI2017」炸弹 线段树优化建图,拓扑,缩点
loj#2255. 「SNOI2017」炸弹 线段树优化建图,拓扑,缩点 链接 loj 思路 用交错关系建出图来,发现可以直接缩点,拓扑统计. 完了吗,不,瓶颈在于边数太多了,线段树优化建图. 细节 ...
- oracle 使用length()函数需要注意的坑!
1.情景展示 筛选出指定字段字符长度既不等于18也不等于15的数据. 2.原因分析 第一步:按字符串度进行分组统计: 第二步:筛选数据. 你会发现,只将length=17统计了出来,长度不存在的数 ...
- 记一次MyBatisPlus问题(如果表名是数据库关键字怎么办)
问题信息:如果表名是数据库关键字怎么办? 正常来说,如果是我们自己写sql的话,给表名加反引号即可解决问题. 但是由于我们使用MyBatisPlus,相关的sql基本上都是封装并自动生成的.如果是这种 ...
- svn无法还原 、svn无法更新
报错: Previous operation has not finished; run 'cleanup' if it was interrupted 上一个操作尚未完成:如果中断,请运行“清理”
- mysql将多条结果拼接成一条结果
1,实际数据 SELECT resource_id, resource_type FROM res_resource_mount 2,拼接之后数据 SELECT c.resource_id, GROU ...