React UI Components Documentation
ReactJS DragDrop Component
The DragDrop component for ReactJS will make any DOM element draggable.
Prerequisites
Refer to ReactJS Getting Started before you start with this help topic.
Configuration
The DragDrop component for ReactJS requires the following imports.
import React from 'react';import ReactDOM from 'react-dom'; import JqxDragDrop from 'jqwidgets-react/react_jqxdragdrop.js';
Then we create our component class. Properties and methods are put as ReactJS props.
class App extends React.Component { render () { return ( <JqxDragDrop restricter={'parent'} dropTarget={'.drop-target'} className="draggable"> <div className="label">I can be dragged only inside my parent</div> </JqxDragDrop> ) }}
Finally we render our class in the desired HTML element:
ReactDOM.render(<App />, document.getElementById('app'));
Events & Properties
In order to bind to any event or change any property, we need a reference to the component.
For that we use the ReactJS "ref" Callback Attribute:
<JqxDragDrop ref='myDragDrop' restricter={'parent'}..... />
Now, when we have a reference, we need to call the desired event/property.
This is done in the componentDidMount() ReactJS Component Lifecycle method.
Events
The dragStart event is triggered when the item is dragged for the first time.
The following example demonstrates how to add an event listener:
Properties
This is how you call props:
Every component have a method setOptions which accepts a object as an argument. This object contains component settings.
Every component also have a method getOptions which returns a object containing the component settings.
DragDrop Examples
Overview
The following example demonstrates how to create a DragDrop component.
Change Dragged Object
The initFeedback is a callback which is executing when the feedback is created.