PDA

View Full Version : Drag and drop in grid with restful store triggers DELETE without POST



smares
27 Apr 2011, 9:36 PM
Hey guys, I am facing another problem with Ext JS... I have a grid bound to a grouping store which uses a JSON reader and writer. The store is restful and should autosave changes. What I implemented for my grid is drag and drop row reordering incl. changing of groups if the item is dragged to another group. Here's my code for the drag and drop:


new Ext.dd.DropTarget(grid.getView().mainBody.dom, {
ddGroup: 'gridDDGroup',
notifyDrop: function(source, e, data) {
var selection = source.dragData.selections;
var target = source.getDragData(e).rowIndex;
if((typeof target !== 'undefined') && (data.rowIndex != target)) {
source.grid.getStore().remove(selection);
source.grid.getStore().insert(target, selection);

source.grid.getSelectionModel().selectRecords(selection);

var roleReference = source.grid.getSelectionModel().hasNext() ? target + 1 : target - 1;
source.grid.getStore().getAt(target).set('role', source.grid.getStore().getAt(roleReference).get('role'));

grid.getView().refresh();
}
return true;
},
notifyOver: function(source, e, data) {
var target = source.getDragData(e).rowIndex;
if((typeof target !== 'undefined') && (data.rowIndex != target)) {
return Ext.dd.DropZone.prototype.dropAllowed;
}
return Ext.dd.DropZone.prototype.dropNotAllowed;
}
});

My problem is that whenever I drag and drop an item, this leads to a DELETE request which is not followed by a POST so the entry is lost in the DB.

I think I will change the logic of the drag and drop reordering and use an order field which I will change to avoid large POST requests as it makes no sense to create a new item when only one attribute changes. But still, how come Ext JS only sends DELETE and not POST?