当前位置: 首页 > article >正文

使用antdv的a-table行拖拽

使用antdv的a-table行拖拽

使用a-table行拖拽,实现上下换行

sortablejs中文网

    <div ref="tableContainer">
        <a-table
                bordered
                size="middle"
                :columns="columns"
                :data-source="[{name: 1}, {name: 2}, {name: 3}]"
                :pagination="false"
                :scroll="{ x: true }"
        >
            <template slot="code" slot-scope="text, row">
                <a-input style="width: 200px" v-model="row.code" placeholder="请输入顺序号"></a-input>
            </template>

            <template slot="action" slot-scope="text, row">
                <a-icon :style="setMultStyle" style="transform: rotate(45deg);color: #1890ff;font-size: 20px;"
                        type="fullscreen"/>
            </template>
        </a-table>
    </div>
export default {
  name: 'sotrTable',
  data(){
     return {
       	  enabled:true,
		  dataSource: [{nodeName: 1}, {nodeName: 2}, {nodeName: 3}],
		  columns: [
		      {
		          title: '名称',
		          dataIndex: 'name',
		          align: 'center'
		      },
		      {
		          title: '顺序号',
		          dataIndex: 'code',
		          align: 'center',
		          scopedSlots: {customRender: 'code'}
		      },
		      {
		          title: '操作',
		          dataIndex: 'action',
		          scopedSlots: {customRender: 'action'},
		          align: 'center',
		          // fixed: 'right',
		          width: 150
		      }
		  ],
     }
  },
       computed: {
            setMultStyle() {
                return {
                    cursor: this.enabled ? 'move' : 'default'
                }
            }
        },
        mounted() {
            this.$nextTick(() => {
                let tableContainer = this.$refs.tableContainer
                this.rowDrop(tableContainer)
            })
        },
        methods: {
            rowDrop(dom) {
                console.log(dom.querySelector('.ant-table>.ant-table-content .ant-table-tbody'))
                new Sortable.create(dom.querySelector('.ant-table>.ant-table-content .ant-table-tbody'), {
                    handle: '.ant-table-row', // 行元素
                    animation: 150,
                    onEnd: ({newIndex, oldIndex}) => {
                        console.log(newIndex, oldIndex)
                        // 拖拽后回调
                        const currRow = this.dataSource.splice(oldIndex, 1)[0]
                        console.log(currRow)
                        console.log(this.dataSource[newIndex])
                        this.dataSource.splice(newIndex, 0, currRow)
                        this.dataSource.forEach((row, index) => {
                            row.sort = index + 1
                        })
                    }
                })
            },
        }
}

http://www.kler.cn/news/343507.html

相关文章:

  • 强化学习笔记之【SAC算法】
  • 学习笔记之指针进阶(10.11)
  • 数据库SQL 某字段按首字母排序_sql按首字母排序
  • 解决PyCharm 2023 Python Packages列表为空
  • 【Docker】03-自制镜像
  • LeetCode讲解篇之746. 使用最小花费爬楼梯
  • 基于SpringBoot+Vue+MySQL的装修公司管理系统
  • 滚雪球学Oracle[5.2讲]:数据库备份与恢复基础
  • MYSQL MVCC多版本并发控制机制与原理、可重复读/读已提交原理
  • vue3中自定义校验函数密码不生效问题
  • Carrier Aggregation 笔记
  • odoo16 视图(View)和界面布局(UI Layout)
  • STM32F407寄存器操作(DMA+SPI)
  • this,this指向
  • SpringBootWeb AOP
  • 胤娲科技:破茧成蝶——具身智能工业机器人引领工业新纪元
  • 尚硅谷rabbitmq 2024 第18-21节 消息可靠性答疑一
  • 压力测试指南-云环境中的压力测试实践
  • 刷题 排序算法
  • Linux与科学计算