PDA

View Full Version : drag drop onto same grid



kesav
20 Aug 2007, 6:54 PM
Is it possible to drag and drop rows on the same grid? I tried using the following code:

// create the Grid
var grid = new Ext.grid.Grid('tab1', {
ds: gridds,
cm: colModel,
autoSizeColumns: true,
enableDragDrop:true,
ddGroup: 'myGroup'
});

grid.render();
myDrop = new Ext.dd.DropTarget(grid.container, {
dropAllowed: 'x-dd-drop-ok',
ddGroup: 'myGroup',
notifyDrop: function(dd, e, data) {
//do something
},
notifyOver: function(dd, e, data) {
//check if the row is allowed, return true or false
}
});

This doesn't work :(( any help would be greatly appreciated.

-kesav

ozilix
20 Aug 2007, 9:51 PM
try this.


grid = new Ext.grid.Grid(gC, {
ds: gridds,
cm: colModel,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:true,
enableDragDrop:true
});
var ddrow = new Ext.dd.DropTarget(this.grid.container, {
ddGroup : 'GridDD',
copy:false,
notifyDrop : function(dd, e, data){
alert('ok');
}

});
grid.render();

kesav
20 Aug 2007, 10:46 PM
Tried this still no luck. Any other tips please...

ozilix
20 Aug 2007, 10:50 PM
is there any error message?

kesav
20 Aug 2007, 10:54 PM
No error message. It just doesn't do any thing. When I try to drag it shows the selected 1 row in green icon but when drop on the grid after other row nothing happns.
You can take a look at http://darwin.314e.com/ext-1.1/TargetlistUI.html
the view source would reveal the code for the page. I appreciate the help, I am stuck at this for last couple of days.

ozilix
20 Aug 2007, 11:01 PM
paste this code on the line 139 and clear alert("data");


var sm=data.grid.getSelectionModel();
var rows=sm.getSelections();
var ds=data.grid.dataSource;
var cindex=dd.getDragData(e)?dd.getDragData(e).rowIndex:ds.data.length-1;
for(i = 0,lenRow=rows.length; i < lenRow; i++) {
rowData=ds.getById(rows[i].id);
if(!this.copy) ds.remove(ds.getById(rows[i].id));
ds.insert(cindex,rowData);
}
data.grid.getSelectionModel().clearSelections();

kesav
20 Aug 2007, 11:10 PM
Wow!!! this works like charm. So basically we need to implement the logic moving rows. Thank you very much for providing the code. Since you are kind enough to help I will ask one more question. How to customize the drag popup instead of displaying 1 selected row I would like to display the current row data. Is it possible to do that?

Once again thank you very much for your instant help.

-kesav

ozilix
20 Aug 2007, 11:12 PM
i think its possible but i don't know how to customize drag popup.

ozilix
20 Aug 2007, 11:24 PM
ext-all-debug line:26917
you must override the getDragDropText function

Ext.grid.Grid.prototype.getDragDropText=function() {
var count = this.selModel.getCount();
return String.format(this.ddText, count, count == 1 ? '' : 's');
};

kesav
20 Aug 2007, 11:25 PM
Thanks for that I'll try that. BTW how to disable dragging columns? I put enableColLock: true but still I am able to drag columns.

Never mind I found.