Event propagation model prevents drop events from firing #520

Closed
austinche opened this Issue Jan 18, 2013 · 6 comments

3 participants

@austinche

Using this example:
http://mleibman.github.com/SlickGrid/examples/example9-row-reordering.html

Even though the 'dropstart' event is bound, it never fires. The 'dropinit' event also does not fire. This appears due to slickgrid requiring stopImmediatePropagation() to be called in the handler. The dropinit event is fired as a result of the draginit event. But because slickgrid stops propagation, the dropinit event is not fired after draginit.

If I manually set up drag, e.g. $('#myGrid').bind('drag', function(){}); then I can get all the drop events to fire as expected.

@mleibman
Owner

If that were the case, wouldn't the example be broken?

@austinche

The example is broken for dropstart. Just put an alert in that function to see it's never called. 'drop' and 'dropend' must be called in a different manner from dropinit and dropstart.

@mleibman mleibman closed this in d068650 Jan 18, 2013
@mleibman
Owner

Looks like this was caused by an unnecessary stopImmediatePropagation() call in the onDrag handler.

@austinche

Thanks. That does look to have fixed the dropstart event. However, it doesn't fix the dropinit event. Just as dropstart appears to be triggered by the drag event, dropinit follows from draginit. But removing the stopImmediatePropagation() from the grid.onDragInit() does not work to enable dropinit. This seems to be because of the way handleDragInit is written.

@mleibman
Owner

Reopening to investigate.

@mleibman mleibman reopened this Jan 18, 2013
@mleibman mleibman closed this in 8122620 Feb 27, 2013
@dholcombe dholcombe added a commit to dholcombe/SlickGrid that referenced this issue Aug 12, 2013
@dholcombe dholcombe Fix #520 - dropstart event not firing
Copied from mleibman Jan 18, 2013 commit
e7ceba2
@pzhukov

As I understand 'dropinit' is still not raised because handler of onDragInit shall call to event.stopImmediatePropagation(). The problem is that jQuery.Drag/Drop uses the same instance of event for 'draginit' and 'dropinit' events. And jQuery (at least version 2.0.3) doesn't dispatch event if event.isImmediatePropagationStopped(). I guess the root cause is in jQuery.Drag/Drop. It "hijacks" event object and resets event.isPropagationStopped() but doesn't reset event.isImmediatePropagationStopped() - it looks like a defect.

But it's strange to use event object to prevent cancelling drag. Is it possible to use return value instead of event.stopImmediatePropagation() in onDragInit handler?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment