Drag and Drop from grid to tree

Hi Team,



I am dragging multiple rows from grid to tree.

I am using tree.attachEvent(“onDrag”,onTreeDrop); event to collect the row ids and sending the the ajax request from same function.

But problem is that it is sending the request multiple times and it is equal to number of rows dragged.

How to avoid multiple request and send only one ajax request using that function?



function onTreeDrop(source_id,target_id){

var source_id = tree.getSelectedItemId();

if(tree.getUserData(target_id,“drop”)==“allow” && target_id != source_id){

var ids=new Array();

for (var i=0; i<mygrid._dragged.length; i++)

order_ids[i] = mygrid._dragged[i].idd ;

new Ajax.Request(’/’,{asynchronous:true,parameters: {ids: ids.join(’,’),source_id: source_id, target_id: target_id}});

}

}





Thanks,

-Agile

var dragged=[];
var drag_time=null;
function onTreeDrop(source_id,target_id){
var source_id = tree.getSelectedItemId();
if(tree.getUserData(target_id,“drop”)==“allow” && target_id != source_id){
dragged.push(target_id);
if (drag_time) window.clearTimeout(drag_time);
drag_time=window.setTimeout(save_data,1);
}
}

function save_data(){
new Ajax.Request(’/’,{asynchronous:true,parameters: {ids: dragged.join(’,’)}});
}