I have two lists #sortable1
and #sortable 2
which are connected sortables, as shown in this example.
You can drag and drop list items from
Try this example
$('#list1').sortable({ connectWith: 'ul' }); $('#list2').sortable({ connectWith: 'ul', receive: function(ev, ui) { if(ui.item.hasClass("number")) ui.sender.sortable("cancel"); } });
Here is my 2 cents. If you don't wish to allow sorting in one of the connected list you can remove it from the containers in the instance object when start even is triggered, so the sorting won't happen at all, and if you need to restore the sorting functionality afterwards, you can recreate the sortable once again or add back removed elements in container array. It would look like this:
start: function(e, ui){
if(ui.item.hasClass('uniqToSortableItem')){
var instance = $(this).sortable( "instance" );
var newContainers = [];
instance.containers.forEach((el)=> {
if(!el.element.hasClass('sortableToDisable')){
newContainers.push(el);
}
});
// in case you need to save initial array just attach it to ui.helper
ui.helper.initialContainersArray = instance.containers;
instance.containers = newContainers;
}
},
stop: function(e, ui){
// returning containers array to previous state if necessary
if(ui.helper.initialContainersArray){
$(this).sortable( "instance" ).containers = ui.helper.initialContainersArray;
}
}