antdesign vue两个表格行拖拽
时间: 2023-10-09 10:16:37 浏览: 109
ant-design-vue(可拖拽table).vue
可以使用ant-design-vue的Draggable组件来实现两个表格行之间的拖拽。您需要将两个表格包裹在Draggable组件中,并设置其属性为“可拖拽”和“可放置”。然后,使用onDragend事件来处理行的拖拽完成后的操作。具体实现可以参考以下示例代码:
```html
<template>
<a-row>
<a-col :span="12">
<a-table
row-key="id"
:columns="columns"
:data-source="tableData1"
:scroll="{ y: 400, x: '100%' }"
></a-table>
</a-col>
<a-col :span="12">
<a-table
row-key="id"
:columns="columns"
:data-source="tableData2"
:scroll="{ y: 400, x: '100%' }"
></a-table>
</a-col>
</a-row>
</template>
<script>
import { Draggable } from "ant-design-vue";
export default {
name: "TableDraggable",
components: {
Draggable
},
data() {
return {
columns: [
{
title: "姓名",
dataIndex: "name",
key: "name"
},
{
title: "年龄",
dataIndex: "age",
key: "age"
},
{
title: "地址",
dataIndex: "address",
key: "address"
}
],
tableData1: [
{
id: 1,
name: "张三",
age: 18,
address: "北京"
},
{
id: 2,
name: "李四",
age: 22,
address: "上海"
}
],
tableData2: [
{
id: 3,
name: "王五",
age: 28,
address: "深圳"
},
{
id: 4,
name: "赵六",
age: 30,
address: "广州"
}
]
};
},
methods: {
handleDragend(event) {
const { newIndex, oldIndex, from, to } = event;
if (from.id === "table1" && to.id === "table2") {
// 从table1拖拽到table2
const item = this.tableData1.splice(oldIndex, 1)[0];
this.tableData2.splice(newIndex, 0, item);
} else if (from.id === "table2" && to.id === "table1") {
// 从table2拖拽到table1
const item = this.tableData2.splice(oldIndex, 1)[0];
this.tableData1.splice(newIndex, 0, item);
}
}
}
};
</script>
<style scoped>
.ant-table-wrapper {
margin-bottom: 16px;
}
</style>
```
阅读全文