PDA

View Full Version : Drag & Drop between two Grid



boston-george
7 Jul 2011, 2:59 AM
Hi guys!
i need to drag from grlRicProd to drop into grlInsOrd

grlIRicProd:
.....


id: 'grlRicProd',
sm: new Ext.grid.RowSelectionModel({
singleSelect: false
}),
enableDragDrop: true, ddGroup: 'grlRicProd-dd',
ddText: 'Prodotto Selezionato',

......


grlInsOrd
.......


id: 'grlInsOrd',
enableDragDrop:
true, ddGroup: 'grlInsOrd-dd',
listeners: {
"render": {
fn: function(grid) {
var ddrow = new Ext.dd.DropTarget(Ext.getCmp('grlInsOrd').getEl(), {
ddGroup: 'grlRicProd-dd', // Data come from??
copy: false,
notifyDrop: function(dd, e, data) {
var sm = Ext.getCmp('grlRicProd').getSelectionModel();
var rows = sm.getSelections();
var cindex = dd.getDragData(e).rowIndex; //cindex IS UNDEFINED! WHY?
if (sm.hasSelection()) {
for (i = 0; i < rows.length; i++) {
Ext.getCmp('grlRicProd').store.remove(Ext.getCmp('grlRicProd').store.getById(rows[i].id)); //THIS WORKS FINE
Ext.getCmp('grlInsOrd').insert(cindex,rows[i]);//ERROR cindex is not defined
}
sm.selectRecords(rows);
}
});
}
}
}

.......
How can i solve it?? thanks

skirtle
7 Jul 2011, 4:36 PM
There is a good example of doing this:

http://dev.sencha.com/deploy/ext-3.4.0/examples/dd/dnd_grid_to_grid.html

The getDragData() method is used internally to populate the dragData property when the mousedown event occurs, you should not be calling it yourself. When the drop occurs you should just grab the dragData.

boston-george
8 Jul 2011, 6:59 AM
Thanks for your answer!

this example is good for me!