Chad Ferguson
Chad Ferguson

Reputation: 3091

Cancel drag and drop between JQGrids

I have requirements to prompt the user for confirmation when dragging and dropping a row between grids. Currently I am trying to assign a class of 'acceptable' to the row if the confirmation is yes and then set the drop_opts to only accept that class. Below is my connection declaration and function for confirmation, I have excluded the code for the rest of the grid as it is not necessary.

$('#MyGrid').jqGrid('gridDnD', { 
connectWith: '#MyGrid2',
onstart: function(evt, ui) {onjqstart(evt, ui)},
drop_opts: { accept: function(el) { return el.hasClass('acceptable'); } }


function onjqstart(evt, ui) {
    var tmp = confirm("Drop it?");
    if (tmp) {
        $(ui.helper).addClass('acceptable');
    }
}

For the accept function it looks like the 'el' variable is a container that is used to hold the draggable row, so it obviously will not have my class added to it and that container does not exist or is not available in my onjqstart event. So any suggestion on how to assign the class to the correct element or a better way to attempt this would be greatly appreciated.

Upvotes: 2

Views: 2432

Answers (1)

Chad Ferguson
Chad Ferguson

Reputation: 3091

I figured out how to do this one. It works out better to use the before drop function. In that function if the user declines the drop it is as simple as setting dropped to false.

$('#MyGrid').jqGrid('gridDnD',{
connectWith: '#MyGrid2',
beforedrop: function(evt, ui, data, source, target) {beforejqdrop(evt, ui, data, source, target)},
ondrop: function(evt, ui, data) {onjqdrop(evt, ui, data)},
dropbyname: 'False',
droppos: 'first',
autoid: 'True',
autoidprefix: 'dnd_',
dragcopy: 'False'});

function beforejqdrop(evt, ui, data, source, target) {
    if (!confirm('is it ok to drop it?')) {
        ui.helper.dropped = false;
    }
}

Upvotes: 3

Related Questions