el-table列宽拖动的原理是通过监听鼠标的mousedown、mousemove和mouseup事件来实现。 1.首先,在表头的每个列的标题处添加一个可拖动的元素,比如一个三角形图标或者一个拖动手柄图标。 2.当用户点击并按住表头上的可拖动元素时,触发mousedown事件。在该事件的处理函数中,记录当前鼠标的坐标,并给document对象添加mousemove和...
有时候我们需要在Element-UI中实现这样的一个效果,鼠标水平拖动,表格也水平滚动,这样可以隐去滚动条! 一、元素增加三个事件 <template> <el-table @mousedown.native="mouseDownHandler" @mouseup.native="mouseUpHandler" @mousemove.native="mouseMoveHandler" ref="tableDataArea" width="100%"> <!-- 省略 --...
// el.style.cursor = 'pointer' el.querySelector('.el-table .el-table__body-wrapper').style.cursor = 'pointer' var mouseDownAndUpTimer = null var mouseOffset = 0 var mouseFlag = false odiv.onmousedown = (e) => { const ePath = composedPath(e) // 拖拽表头不滑动 if (ePath.some...
实现 在template 模版中 定义mousedown方法,表示开始拖拽,并拿到记录拖拽元素标识信息 <el-table-column header-align="center"type="index"align="center"label="":width="60"><template#default="{ row, $index }"><el-space:class="filedInfoClass['drag-table-item']"@mousedown="dragHandle.dragStart(row...
('.el-table__header-wrapper tr'); this.sortable = Sortable.create(wrapperTr, { animation: 180, delay: 0, onEnd: this.onSortEnd }); }, handleMouseDown(event, index) { this.startIndex = index; this.startX = event.clientX; document.addEventListener('mousemove', this.handleMouseMove); ...
简介:基于elementUI的el-table组件实现按住某一行数据上下滑动选中/选择或取消选中/选择鼠标经过的行 实现代码 <template><div :class="$options.name"><el-tablestyle="user-select: none"ref="table":data="tableData":row-class-name="row_class_name"@mousedown.native="mousedownTable"@row-click="row_cl...
简介:基于elementUI的el-table组件实现按住某一行数据上下滑动选中/选择或取消选中/选择鼠标经过的行 实现代码 <template><div :class="$options.name"><el-tablestyle="user-select: none"ref="table":data="tableData":row-class-name="row_class_name"@mousedown.native="mousedownTable"@row-click="row_cl...
简介:基于elementUI的el-table组件实现按住某一行数据上下滑动选中/选择或取消选中/选择鼠标经过的行 实现代码 <template><div :class="$options.name"><el-tablestyle="user-select: none"ref="table":data="tableData":row-class-name="row_class_name"@mousedown.native="mousedownTable"@row-click="row_cl...
el-table 横向拖拽 在utils/diretives.js 文件中创建自定义指令: importVuefrom"vue";/** * 表格横向拖拽 */Vue.directive("tableDrag",{inserted:function(el){el=el.getElementsByClassName("el-table__body-wrapper")[0];el.style.cursor="grab";el.onmousedown=function(){letgapX=event.clientX;let...
需求描述 vue-element-admin开发过程中需要对el-table行进行排序(即每一行可以上下移动),然后将排序后的数据传给后台更新数据。该表格无分页。 问题分析 方法一:可以采用在每条数据中加两个上下移动的按钮,每次移动一行。该方法实现简单,不过要连续移动的时候需要多次