【vue开发】基于vue+element-ui框架的表格拖拽排序demo
表格
<el-table :data="tableData.filter(data => !fieldKeyWords || data.description.includes(fieldKeyWords))" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" style="width: 100%; position: absolute" row-key="fldId" height="100%" > <el-table-column prop="" label="操作" min-width="135"> <template slot-scope="scope"> <el-button type="text" icon="el-icon-edit" class="op-btn" @click="editField(scope.row)" >编辑 </el-button> <el-button icon="el-icon-delete" type="text" class="btn-delete btn-el-no-padding op-btn" show-overflow-tooltip @click="removeField(scope.row)" >删除 </el-button> </template> </el-table-column> <el-table-column header-align="center" align="center" prop="isShow" label="是否展示"> <template slot-scope="scope"> <el-switch v-model="scope.row.isShow" @change="toggleShow(scope.row)"></el-switch> </template> </el-table-column> <el-table-column prop="fldId" label="字段ID" show-overflow-tooltip width="200" /> <el-table-column prop="description" label="字段名称" show-overflow-tooltip width="160" /> <el-table-column prop="fldType" label="字段类型" width="110" show-overflow-tooltip> <template slot-scope="scope"> {{ transformFldType(scope.row.fldType) }} </template> </el-table-column> <el-table-column prop="fldDataType" label="数据类型" show-overflow-tooltip width="110"> <template slot-scope="scope"> {{ transformFldDataType(scope.row.fldDataType) }} </template> </el-table-column> <el-table-column prop="fldDataLength" label="字段长度" show-overflow-tooltip align="center" width="80"> <template slot-scope="scope"> {{ scope.row.fldDataPrecision ? `${scope.row.fldDataLength},${scope.row.fldDataPrecision}` : scope.row.fldDataLength }} </template> </el-table-column> </el-table>
js排序
// 行拖拽 rowDrop() { // 此时找到的元素是要拖拽元素的父容器 const tbody: any = document.querySelector('.el-table__body-wrapper tbody') const _this = this Sortable.create(tbody, { // 指定父元素下可被拖拽的子元素 draggable: '.el-table__row', onEnd({ newIndex, oldIndex }: any) { const currRow = _this.tableData.splice(oldIndex, 1)[0] _this.tableData.splice(newIndex, 0, currRow) _this.handleFieldSort(_this.tableData) } }) }
本文来自博客园,作者:JeckHui;
个人主页:前端实用站点推荐; 热榜资讯早读:热榜资讯-导航;
转载请注明原文链接:https://www.cnblogs.com/xiaohuizhang/p/16051337.html
分类:
vue开发
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)