首页 > 其他分享 >el-table 拖动排序 sortablejs

el-table 拖动排序 sortablejs

时间:2023-08-18 13:55:26浏览次数:31  
标签:oldIndex el sortablejs let table newIndex

参考:https://blog.csdn.net/glpghz/article/details/124359331

官网:http://www.sortablejs.com/index.html

安装

cnpm install sortablejs --save

引入

import Sortable from "sortablejs";

table加锚点

<el-table
  id="ability-table"

加载后

  mounted() {
    this.rowDrop();
  },
    // 排序表格
    rowDrop() {
      let el = document.querySelector("#ability-table .el-table__body-wrapper tbody");
      let self = this;
      let ops = {
        animation: 150,
        onEnd({ newIndex, oldIndex }) {
          if (newIndex > oldIndex) {
            let mid = newIndex;
            newIndex = oldIndex;
            oldIndex = mid;
          }
          let beforeNum = 0;
          for (let index = newIndex; index <= oldIndex; index++) {
            // 第一个换成最后一个的orderNum
            if (index == newIndex) {
              beforeNum = self.categoryList[index].orderNum;
              let lastNum = self.categoryList[oldIndex].orderNum;
              self.$set(self.categoryList[index], "orderNum", lastNum);
            } else {
              // 从第二个开始换成上一个的orderNum
              let num = self.categoryList[index].orderNum;
              self.$set(self.categoryList[index], "orderNum", beforeNum);
              beforeNum = num;
            }
          }
          // 这里要保存数据更新list,不然下次就更新不了了
          self.saveListOrder();
        },
      };
      new Sortable(el, ops);
    },

 

标签:oldIndex,el,sortablejs,let,table,newIndex
From: https://www.cnblogs.com/jqynr/p/17640280.html

相关文章

  • 导出运营数据Excel报表_需求分析和设计
       ......
  • WPF加载GIF的五种方式(Storyboard / WpfAnimatedGif / ImageAnimator / PictureBox / M
    部分内容参考博文WPF如何显示gif一、使用Storyboard效果:  (1)页面xaml:<Windowx:Class="PlayGifDemo.StoryboardWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2......
  • 解决小程序报错 getLocation:fail the api need to be declared in the requiredPriva
    一、unipp项目打开uniapp项目的配置文件manifest.json,选择“源码视图”。/*小程序特有相关*/"mp-weixin":{"appid":"你的开发者id","setting":{"urlCheck":true,"es6":true,"postcss":......
  • jquery.nice-select 教程
    jQueryNiceSelect是一个基于jQuery的优雅选择框插件,它可以美化网页中的下拉选择框。下面是使用jQueryNiceSelect的基本步骤:引入jQuery和jQueryNiceSelect:在你的HTML文件中,首先需要引入jQuery和jQueryNiceSelect的脚本文件。你可以从官方网站下载最新版本的......
  • shell 学习之文本处理工具
    视频:07_小工具使用diff【正常模式】_哔哩哔哩_bilibili1.grep 2.cut 3.sort  4.uniq 5.tee从标准输入读取并写到标准输出和文件,即双向覆盖重定向(屏幕输出/文本输入)。 6.diff 逐行比较文件的不同。 语法:diff[选项]file1file2 1)正常显示......
  • Android串口调试 libserial_port.so: has text relocations
    遇到问题:Android串口调试libserial_port.so:hastextrelocations解决方法1在Android.mk文件中加入:LOCAL_LDFLAGS+=-fPIC,重新编译Google开源库的源码,生成.so库LOCAL_PATH:=$(callmy-dir)include$(CLEAR_VARS)TARGET_PLATFORM:=android-3......
  • OBS Studio 30.0公测版可在Linux平台添加对Intel QSV支持
        据了解,日前OBSStudio30.0公测版发布,并且支持Linux平台上添加对IntelQSV(QuickSyncVideo)的支持,同时还为DeckLink输出提供HDR播放支持。OBSStudio30.0公测版还改进了GUI,重新设计了状态栏,帮助用户更有组织和结构化地管理内容,此外还引入了更具代表性和可识别性......
  • linux shell wc统计文件行数
    语法:wc[选项]文件…说明:该命令统计给定文件中的字节数、字数、行数。如果没有给出文件名,则从标准输入读取。wc同时也给出所有指定文件的总统计数。字是由空格字符区分开的最大字符串。该命令各选项含义如下:-c统计字节数。-l统计行数。-w统计字数。这些选项可以......
  • Flask + xlwt 以流形式返回Excel文件
    flaskfromioimportBytesIOimportxlwtfromflaskimportsend_file@app.route('/')defget_excel(): bio=BytesIO() wb=xlwt.Workbook(encoding='utf8') sheet=wb.add_sheet('Sheet1',cell_overwrite_ok=True) #写入表头 sty......
  • elementUI使用分页器以及搜索条件
    <template><div><!--搜索--><divstyle="float:left"><el-form:inline="true":model="formInline"class="demo-form-inline"size="mini"><el-form-......