Using the Drag-and-Drop APIDuring a dragging process, a DragDropEvent JavaScript object is available for all methods that are assigned to supported drag and drop attributes. The object is ready to be used when drag-begin phase is started, and it persists until the end of the drag-complete phase. DragDropEvent object offers several methods that enhances the drag and drop process.
The getSource() and getTarget() methods The getTransferObject() and setTransferObject() methods Commonly, when dragging process begins, the transfer data is identified at this phase. This data is represented in JavaScript valid data-type or object. To set the transferable data, a user can call the DragDropEvent’s setTransferObject() method and pass the transferable data object as the method parameter. As the drag and drop is completed, the transferable data needs to be transferred to the targeted object. To get the transferable data, a user can call the DragDropEvent’s getTransferObject() method. If nothing is set earlier, the method will return null. Example The Source Component <xtable .. The Target Component <xtree The User-Defined JavaScript Code
<xscript>
/******************************
SOURCE RELATED METHODS
******************************/
// beginDragging is attached to the xtable drag-begin attribute
function beginDragging(dragDropEvent)
{
// get the source object using DragDropEvent's getSource() method
var source = dragDropEvent.getSource();
...
// do object specific action (such as highligh row, etc)
...
// setting transferable data into DragDropEvent's setTransferObject() method
var data = "Special Mission Data";
dragDropEvent.setTransferObject(data);
}
// exitSource is attached to the xtable drag-exit attribute
function exitSource(dragDropEvent)
{
// ... do something or nothing ...
}
// completeDragDrop is attached to the xtable drag-exit attribute
function completeDragDrop(dragDropEvent)
{
//... do something or nothing ...
}
/******************************
TARGET RELATED METHODS
******************************/
// enterTarget is attached to the xtree drag-enter attribute
function enterTarget(dragDropEvent)
{
// ... do something or nothing ...
}
// overTarget is attached to the xtable drag-drop attribute
function overTarget(dragDropEvent)
{
//... do something or nothing ...
}
// transferData is attached to the xtable drag-drop attribute
function transferDataCompletion(dragDropEvent)
{
// get the source object using DragDropEvent's getSource() method
var source = dragDropEvent.getSource();
// get the target object using DragDropEvent's getTarget() method
var target = dragDropEvent.getTarget();
// get the transferable data that was set earlier
var data = dragDropEvent.getTransferObject();
// perform component specific actions...
// such as:
// target.insertNode(data) to insert a new node in a tree
// source.removeRow(source.selectedRowIndex) to remove the selected row
....
}
</xscript>
Next: Applying Drag-and-Drop
to xtable | |||
|
COPYRIGHT © 1997–2006
JWAY GROUP, Inc. |
|||