Skip to main content

How to use drag and drop in ant design?

What I want is an example about how to make the drag and drop of my Table that works properly, but I cannot figure out how to make it works in (functional components)

My code :

   function Preview() {
      const { name } = useParams();
      const [fieldsOfForm, setFieldsOfForm] = useState([]);
      const [selectedForm, setSelectedForm] = useState([]);

      const columns = [
        {
          title: 'Posição',
          dataIndex: 'pos',
          width: 30,
          className: 'drag-visible',
          render: () => 
          <MenuOutlined style=/>
        },
        {
          title: "Form Name",
          dataIndex: "field",
          key: "field",
          render: (text) => <a>{text}</a>,
        },
        {
          title: "Tipo",
          dataIndex: "fieldtype",
          key: "fieldtype",
        },
      ];
 
      useEffect(() => {
        let mounted = true;
        let loadingStates = loading;
        if (mounted) {
          setFieldsOfForm(location.state);
          loadingStates.allFields = false;
          setLoading(false);
        }
        return () => (mounted = false);
      }, [selectedForm]);
    
    
      return (
           //Some jsx....
             <Row gutter={1}>
                <Col span={1}></Col>
                  <Table dataSource={fieldsOfForm} 
                    columns= {columns}/>
              </Row>
            // More jsx...          
      );
    }
    
    export default Preview; 

Everything that I found on internet about this drag and drop from the lib of antd is in class component , but I wanted to make it works in my functional one.

Example that I found : multi row drag-able table (antd)

I want some example in function component if someone has tried it already and could help me ?

Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW

Comments