During drag-n-drop operations between different components as well as different instances of a component, it's vital to ensure that data items from the source component receive adequate representation in the target one.
The externalData property features a function responsible for dragging as value (in case you work with different components).
{
view:"tree",
drag:true,
select:true,
data:[],
externalData:grid2tree
};
The property function takes two parameters - data and id:
When moved to the target component, the item retains the ID it had in the source component, unless the target already has an item with this ID. In this case, the ID will be set randomly, while the initial ID will be stored in the function.
Take for instance, an app containing two trees, a DataView and DataTable. The tree dataset includes items with data.value items, while DataView and DataTable have data.title and data.rank. To enable drag-n-drop within the whole group, you need two functions:
1 . The function that will populate DataView and DataTable.
function tree2grid(data, id){
data.rank = data.rank || -1;
data.title = data.title || data.value;
return data;
}
Notice the "OR" logic here:
2 .The function that will populate tree with dragged data is the following:
function grid2tree(data, id){
data.value = data.value || data.title;
return data;
}
Here only data.value matters. The tree will take the dragged-and-dropped data.value value from the other tree, or the data.title value from either of the DataTables.
Related sample: Basic Drag-and-Drop