Reputation: 1137
I'm trying to create a table with sortable rows with jQuery UI. I already have this working, but I intend on only sort some rows (not all of them) based on a checkbox.
I uploaded the code to http://jsfiddle.net/detesto/7Tcgc/3/
When the checkbox changes, I add or remove the class that should trigger the sortable row. The problem is that when it is removed, it doesn't work as expected.
I also tried doing a refresh on the sortble $("#selector").sortable("refresh");
but this doesn't work for me either.
I have it working by cancelling the event if the user drags a non-valid row, but I would like to prevent this altogether.
Can this be prevented?
Thanks in advance.
Upvotes: 1
Views: 2911
Reputation: 397
change to this code
$(document).ready(function () {
clearTimeout(timeoutOnce);
timeoutOnce = setTimeout(reorderRows, 300);
$("#fileTable tbody").sortable({
helper: fixHelper,
items: "> tr.doSort",
cancel: ".noSort" //---- add
}).disableSelection();
}).on("click", ".enableDisable", function () {
if ($(this).is(":checked")) {
$(this).closest("tr").removeClass("noSort").addClass("doSort");
//$("#fileTable tbody").sortable("refresh"); // --- remove
} else {
$(this).closest("tr").addClass("noSort").removeClass("doSort");
//$("#fileTable tbody").sortable("refresh"); // --- remove
}
});
Upvotes: 2