vue + sortable 拖拽移动表格

30 篇文章 0 订阅
9 篇文章 0 订阅

vue + sortable 拖拽移动表格

<el-table sticky ref="list" :max-height="listScope.height" row-key="id" :data="page_info.data.data">
    <el-table-column :key="'col_'+index" :prop="dropCol[index].field" :label="item.title"
                        v-for="(item,index) in col"
                        :min-width="item.title=='车型'||item.title=='车架号'?200:(item.title.length *14)+50">
     </el-table-column>
</el-table>

col 和 dropCol 可以是同一个数组

columnDrop() {
                    const _this = this;
                    const wrapperTr = document.querySelector(".el-table__header-wrapper tr");
                    let Nodeth = this.$el.querySelector('.el-table__header-wrapper tr')
                    Sortable.create(wrapperTr, {
                        animation: 180,
                        delay: 0,
                        onEnd: evt => {

                            console.log(evt.oldIndex)
                            console.log(evt.newIndex)

                            // const newList = this.dropCol.slice()
                            // const targetRow = this.dropCol.splice(evt.oldIndex, 1)[0]
                            var storage = Nodeth.children[evt.newIndex], NodeoldLi = Nodeth.children[evt.oldIndex];
                            // 先删除移动的节点
                            Nodeth.removeChild(storage)
                            // 再插入移动的节点到原有节点,还原了移动的操作
                            if (evt.newIndex > evt.oldIndex) {
                                Nodeth.insertBefore(storage, NodeoldLi)
                            } else {
                                Nodeth.insertBefore(storage, NodeoldLi.nextSibling)
                            }
                            // 更新items数组
                            var item = this.dropCol.splice(evt.oldIndex, 1)
                            this.dropCol.splice(evt.newIndex, 0, item[0])
                        }
                    });
                },

wrapperTr 可删除 替换为 Nodeth

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值