I want a row in a jQuery UI Sortable to be sortable only if it has a cansort class. I have it set to cancel: ':not(.cansort)' but it refuses to let me sort anything at all, including the rows that have the cansort class.
I know I can add a disabled class explicitly, but I use the cansort class for other purposes, so that means each time I made something sortable I would have to remove the disabled class and add the cansort class. I don’t want to have to add and remove a class each time I toggle something to be sortable.
I don’t want to restrict what’s sortable in the items property because every element can be sortable and I only dynamically toggle it on and off using the cansort class.
The reason for this is the way that the
canceloption is processed by theui.mousewidget (a widget used by several jQueryUI widgets to handle mouse events). Check out this line of code:What this means is that your selector gets run with the
closeston the element that wasmousedowned on. So lets take anli.cansortsortable item. That will generate a jQuery selector that looks something like this:This will always return a length of
1, because the parentulfor all the sortablelis does not have the.cansortclass. This means with that kind of selector, the sorting will always be canceled.Luckily, this is easy to get around if you just include the tag name in your
cancelselector:Here’s an example: http://jsfiddle.net/7hSnc/ (try removing the
lifrom thecancelselector)