-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
table能够像antd react版本那样提供行数据拖拽排序的demo #1804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
同样遇到这个需求,暂时没想到解决文案,感觉不是很好加其它拖拽组件 |
这个需求我使用H5的Draggable自己封装实现的。 |
不晓得这个需求使用Vue-Dragable怎么实现操作,能贴一下代码吗? |
@SeasonGuo 说的对,原理就是用dragable组件绑定拖拽事件,然后改变column的width属性就可以了 |
https://codesandbox.io/s/draggable-table-e07sm 用vue-draggable简单做了一个,没仔细测 |
确实,对于我的项目来说稍微改动一下就能用了,我使用的是Ant Design Pro of Vue的 |
你可以贴一个你原生js实现的版本demo |
请教个问题 这个地方为何要使用事件总线去进行消息的传递呢 直接emit会有什么问题吗 |
直接emit好像是接收不到吧,中间有很多层组件 |
好的这个我了解了!还有个问题就是示例里面的move方法貌似不起作用呢 |
我想问下,这个问题解决了么 |
后面看了一下其实不需要用move方法,Vue.Draggable会自动修改数据 |
这里可以利用provide一个onDrag,然后在wrapper里面调用this.onDrag这种方式,比事件总线方便和优雅点 |
vue3 antd antdesign table 拖拽实现 Hook 实现/* Vue table draggable Hook */
/* antd vue 版本 table 拖拽 hook */
/**
* antd vue 版本 table 拖拽 hook
* @param dataSource table数据集合
* @returns customRow 行属性方法
*/
function DraggableHook<T>(dataSource: Array<T>) {
let dragItem: T;
let targItem: T;
const customRow = (record: T) => {
return {
draggable: true,
ondrag(e: DragEvent) {
dragItem = record;
},
ondrop(e: DragEvent) {
targItem = record;
},
ondragend(e: DragEvent) {
if (dragItem !== targItem) {
const dragItemIndex = dataSource.indexOf(dragItem);
const targItemIndex = dataSource.indexOf(targItem);
// 解构交换
[dataSource[dragItemIndex], dataSource[targItemIndex]] = [
dataSource[targItemIndex],
dataSource[dragItemIndex],
];
}
},
ondragover(e: DragEvent) {
return false;
},
};
};
return customRow;
}
export default DraggableHook; 用法<template>
<a-table :dataSource="dataSource" :columns="columns" :customRow="customRow" />
</template>
const customRow = DraggableHook<TabItem>(dataSource);
setup(){
return {
customRow
}
} |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
What problem does this feature solve?
希望table能够像antd react版本那样提供行数据拖拽排序的demo
What does the proposed API look like?
提供完成demo
The text was updated successfully, but these errors were encountered: