An absolutely common sortable case:
- Item
Try this example
$('#list1').sortable({ connectWith: 'ul' }); $('#list2').sortable({ connectWith: 'ul', receive: function(ev, ui) { if(ui.item.hasClass("number")) ui.sender.sortable("cancel"); } });
The sort
function callback does the same for sort as drag for draggable (demo):
$("#sortable").sortable({
sort: function() {
if ($(this).hasClass("cancel")) {
$(this).sortable("cancel");
}
}
});
Returning false
as fudgey suggests works great for making things dynamically unsortable, but there's also a cancel option in the sortable config which lets you set up static unsortables as well:
$("#sortable").sortable({
// this prevents all buttons, form fields, and elemens
// with the "unsortable" class from being dragged
cancel: ":input, button, .unsortable"
});
Sortable has a "cancel" capability invoked using sortable('cancel')
.
From the docs: "Cancels a change in the current sortable and reverts it to the state prior to when the current sort was started." See http://api.jqueryui.com/sortable/#method-cancel.
Example usage:
$("#sortable").sortable({
stop: function(e, ui) {
if ("I need to cancel this") {
$(ui.sender).sortable('cancel');
}
}
});