How can I support my antd design table to have drag and drop?
I want my users to be able to reorder the rows in a table by dragging and dropping
2 Replies
Hi @BlackBearFTW. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To support drag-and-drop functionality in an Ant Design table using the refine framework, you can utilize the
useDrag
and useDrop
hooks from the react-dnd
library. Below are the steps to achieve this:
1. Install react-dnd
and react-dnd-html5-backend
:
2. Create a Draggable Row Component:
Define a component that will represent each row in the table and make it draggable using the useDrag
hook.
3. Create a Droppable Table Component:
Define a component that will represent the table and handle the drop logic using the useDrop
hook.
4. Use the Draggable Table Component:
Finally, use the DraggableTable
component in your application.
```jsx
import React, { useState } from "react";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import DraggableTable from "./DraggableTable";
const App = () => {
const [data, setData] = useState([
{ key: '1', name: 'John Brown', age: 32 },
{ key: '2', name: 'Jim Green', age: 42 },
{ key: '3', name: 'Joe Black', age: 32 },
]);
const columns = [
{ title: 'Name', dataIndex: 'name', key: 'name' },
{ title: 'Age
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@490961337896402944> kapa.ai is still learning and improving, please let us know how it did by reacting below