hootsuite / grid

Drag and drop library for two-dimensional, resizable and responsive lists
http://hootsuite.github.io/grid/
Apache License 2.0
3.57k stars 279 forks source link

Enabling and disabling drag and drop #107

Open capitanjacksparrow opened 7 years ago

capitanjacksparrow commented 7 years ago

Is it possible to enable and disable drag and drop on the basis of mouse or touch events? I tried by setting dragAndDrop property in this way, on a click event:

$('#grid').gridList({dragAndDrop: false});

However, the layout changes (it doesn't fit the vertical direction anymore) and the widgets behavior becomes unstable.

bojan88 commented 7 years ago

Try this:

function disableDrag() {
  $('.grid-item').draggable('disable');
  $('.grid-item').bind('dragstart', gridItemDisableHandler);
}

function enableDrag() {
  $('.grid-item').draggable('enable');
  $('.grid-item').unbind('dragstart', gridItemDisableHandler);
}

Note that you have to add grid-item class to the items.