Sortable icon indicating copy to clipboard operation
Sortable copied to clipboard

Is there a way to programmatically drag and drop? (Without the mouse drag event)

Open inchrvndr opened this issue 7 years ago • 5 comments

Here is my fiddle : https://jsfiddle.net/a9rkz2pg/

The blocks in the widgets group can be dragged using the mouse drag event, as a clone and dropped into Group 1 or Group 2,3,4.. (appears on click of plus button)

But, is there a way this can be done programmatically, either by knowing the id/class of the draggable or it’s text content?

new Sortable($('#widgets-1')[0], {
  group: {
    name: 'letters',
    put: false,
    pull: 'clone',
  },
  setData: function(dataTransfer, element) {
    dataTransfer.setData('text', element.textContent);
  },
  sort: false
});

Any help would be much appreciated. Thank you!

inchrvndr avatar Mar 18 '18 08:03 inchrvndr

This would be such a useful feature! I am currently working on something where we need to programmatically set the order back to a pre-defined order (or the page load order) if someone clicks a "reset" button. Still trying...

onKeyBoard avatar Jul 19 '18 18:07 onKeyBoard

Any luck?

HMAZonderland avatar Oct 08 '18 14:10 HMAZonderland

This is exactly what I was looking for, but don't see any way.

kinjal-codes avatar May 04 '19 20:05 kinjal-codes

edit: updated link Hi, I'm working on the ember addon and came up with this https://github.com/SortableJS/ember-sortablejs/blob/master/addon-test-support/dndsimulator.js

It should help.

lvegerano avatar Jul 14 '19 15:07 lvegerano

@lvegerano hey be honest, did you decompiled Hogwarts "Wingardium Leviosa" spell? Because it feels like it!!

P.S. this is going to help a lot in best open-source task manager called Vikunja. If this brutal Dark Magic will get approved of couse 😆

Also be careful with elements seletion folks, that code calculates distance between centers of source & target elements.

executed avatar Jan 27 '25 15:01 executed