Disable sorting by sortable item except connectWith

Is it possible to disable sorting by the 'sortable' element, but sorting still works with 'connectWith'?

+4
source share
4 answers

This will return the item in list1 to its original location if it does not appear in list2 (I call it self-decay).

$("#list1").sortable({ connectWith: ".connected-fields", beforeStop: function(event, ui) { // Don't allow resorting in list1... would call cancel here, but there is a jquery 1.7 bug so we // need to do the check here but do the cancel in "stop" below. @see http://bugs.jqueryui.com/ticket/6054 $(this).sortable("option", "selfDrop", $(ui.placeholder).parent()[0] == this); }, stop: function(event, ui) { var $sortable = $(this); if ($sortable.sortable("option", "selfDrop")) { $sortable.sortable('cancel'); return; } } }); $("#list2").sortable({ connectWith: ".connected-fields" }); 
+3
source

I would just delete the original sortable logic and apply a class attached to one sortable one. So, for example, you have three functions for two lists you sort. If one of them is sorted = disabled, delete the sort class with conenctWith parameters and apply one sort class to the list with which you were associated. If you need to stop it, then do the same with the other.

Example:

 $('sortBoth').sortable({connectWith: $('.sortListToConnect)}); $('.sortList2').sortable(); $('.sortList3').sortable(); 

Delete or add a class to each list accordingly for how you need it to function. An easy way to handle this. I hope I quickly formulated this quite clearly. Happy coding :)

0
source

You can try this code for disable sortable :

 $( ".selector" ).sortable( "disable" ); 

You can learn more from this link.

And this link is for the disable method.

-1
source

You can undo the items in the left columns from self-sorting and still use them for connectWith

http://api.jqueryui.com/sortable/#option-cancel

-1
source

All Articles