I have table rows that are sortable depending on whether certain radio buttons are checked or not. The sortables are initialized on document.ready
as follows:
I ran into the same problem, that the items
option doesn't seem to remove items which had been previously enabled.
The cancel
option, however, does. Note that the disabled items will shift around to make room for the sortable ones (the spot is still available as a drop target), but dragging the disabled items themselves will not work. Using a disabled
class also makes it easy to change the style based on whether or not the item is sortable (see on jsfiddle).
The code here is partially based on Bah Bah the Lamb's answer, but it has been greatly tidied and simplified.
The html:
-
Item 1
-
Item 2
-
Item 3
The jQuery:
$("#sorted-list").sortable({
cancel:".disabled"
});
// add or remove the 'disabled' class based on the value of the checkbox
$("#sorted-list input").click(function() {
if (this.checked) {
$(this.parentElement).removeClass("disabled");
} else {
$(this.parentElement).addClass("disabled");
}
});
The CSS:
li {
border: 1px solid #aaa;
background-color: #eee;
color:#555;
padding: 5px;
}
.disabled {
color:#ffffd;
}