Clear Up
SharpKit Reference

DropZone Class

This class provides a container DD instance that allows dropping on multiple child target nodes.

By default, this class requires that child nodes accepting drop are registered with Ext.dd.Registry. However a simpler way to allow a DropZone to manage any number of target elements is to configure the DropZone with an implementation of getTargetFromEvent which interrogates the passed mouse event to see if it has taken place within an element, or class of elements. This is easily done by using the event's getTarget method to identify a node based on a Ext.DomQuery selector.

Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over a drop target, that target is passed as the first parameter to onNodeEnter, onNodeOver, onNodeOut, onNodeDrop. You may configure the instance of DropZone with implementations of these methods to provide application-specific behaviour for these events to update both application state, and UI state.

For example to make a GridPanel a cooperating target with the example illustrated in DragZone, the following technique might be used:

  
myGridPanel.on('render', function() {
            myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, {
            // If the mouse is over a grid row, return that node. This is
            // provided as the "target" parameter in all "onNodeXXXX" node event handling functions
            getTargetFromEvent: function(e) {
            return e.getTarget(myGridPanel.getView().rowSelector);
            },
            // On entry into a target node, highlight that node.
            onNodeEnter : function(target, dd, e, data){
            Ext.fly(target).addCls('my-row-highlight-class');
            },
            // On exit from a target node, unhighlight that node.
            onNodeOut : function(target, dd, e, data){
            Ext.fly(target).removeCls('my-row-highlight-class');
            },
            // While over a target node, return the default drop allowed class which
            // places a "tick" icon into the drag proxy.
            onNodeOver : function(target, dd, e, data){
            return Ext.dd.DropZone.prototype.dropAllowed;
            },
            // On node drop we can interrogate the target to find the underlying
            // application object that is the real target of the dragged data.
            // In this case, it is a Record in the GridPanel's Store.
            // We can use the data set up by the DragZone's getDragData method to read
            // any data we decided to attach in the DragZone's getDragData method.
            onNodeDrop : function(target, dd, e, data){
            var rowIndex = myGridPanel.getView().findRowIndex(target);
            var r = myGridPanel.getStore().getAt(rowIndex);
            Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id +
            ' on Record id ' + r.id);
            return true;
            }
            });
            }
            

See the DragZone documentation for details about building a DragZone which cooperates with this DropZone.

Namespace: Ext.dd

Methods

Name Description
getTargetFromEvent(object) Returns a custom data object associated with the DOM node that is the target of the event. By default this looks up the event target in the Ext.dd.Registry, although you can override this method to provide your own custom lookup.
onContainerDrop(DragSource, object, object) Called when the DropZone determines that a Ext.dd.DragSource has been dropped on it, but not on any of its registered drop nodes. The default implementation returns false, so it should be overridden to provide the appropriate processing of the drop event if you need the drop zone itself to be able to accept drops. It should return true when valid so that the drag source's repair action does not run.

This is a template method. a hook into the functionality of this class. Feel free to override it in child classes.

onContainerOver(DragSource, object, object) Called while the DropZone determines that a Ext.dd.DragSource is being dragged over it, but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so it should be overridden to provide the proper feedback if necessary.

This is a template method. a hook into the functionality of this class. Feel free to override it in child classes.

onNodeDrop(object, DragSource, object, object) Called when the DropZone determines that a Ext.dd.DragSource has been dropped onto the drop node. The default implementation returns false, so it should be overridden to provide the appropriate processing of the drop event and return true so that the drag source's repair action does not run.

This is a template method. a hook into the functionality of this class. Feel free to override it in child classes.

onNodeEnter(object, DragSource, object, object) Called when the DropZone determines that a Ext.dd.DragSource has entered a drop node that has either been registered or detected by a configured implementation of getTargetFromEvent. This method has no default implementation and should be overridden to provide node-specific processing if necessary.
onNodeOut(object, DragSource, object, object) Called when the DropZone determines that a Ext.dd.DragSource has been dragged out of the drop node without dropping. This method has no default implementation and should be overridden to provide node-specific processing if necessary.

This is a template method. a hook into the functionality of this class. Feel free to override it in child classes.

onNodeOver(object, DragSource, object, object) Called while the DropZone determines that a Ext.dd.DragSource is over a drop node that has either been registered or detected by a configured implementation of getTargetFromEvent. The default implementation returns this.dropAllowed, so it should be overridden to provide the proper feedback.

This is a template method. a hook into the functionality of this class. Feel free to override it in child classes.

© Copyright 2005-2011 SharpKit. All rights reserved.