1

I'm a beginner in jQuery and I can't found a solution: I'm using Sortable with a table. But the default re-ordering method isn't good for me: I don't want insert the dragged item - I want swap the dragged item and the "current" item (where the mouse pointer is).

 $(".timetable").sortable({
     items: "td.ora",
     sort: function(event,ui) {
            // what should I write here?
     });

I think should overwrite the sort event but I don't know how.

idmean
  • 14,540
  • 9
  • 54
  • 83
uzsolt
  • 5,832
  • 2
  • 20
  • 32

1 Answers1

4

This question has a solution for Sortable (see the workaround at the bottom of the question):

jQuery sortable obtain 2 elements being swapped

But I think the more elegant solution is the Swappable plugin:

http://www.eslinstructor.net/demo/swappable/swappable_home.html

Community
  • 1
  • 1
mccannf
  • 16,619
  • 3
  • 51
  • 63
  • I'm see swappable plugin, but it doesn't work for me, you can check e.g. the list demo on homepage: many times can't swap two elements. In my case *never* can swap... I'll see first method. – uzsolt Oct 31 '12 at 14:19
  • The swappable plugin worked beautifully for me. You have to define the draggable items yourself though AND make sure the cursor is not over your dragged item, otherwise it won't work. `$('#my-list').swappable({items: 'li', cursorAt: {top:-10}});`. The plugin is a real jquery ui-plugin, so it will accept all the deafult ui parameters and events as well. – Jules Colle Mar 28 '13 at 09:21