Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disabling individual items in knockout-sortable

In knockout-sortable, I know that you can disable a sortable list using isEnabled in the sortable binding. I also know you can disable moving items using cancelDrop in a beforeMove function. The problem is, isEnabled disables the whole list, and cancelDrop can only be called after the item is already dragged and dropped onto another sortable.

Is there a way to disable sortable's click/drag behavior on certain contained items?

like image 453
Ross Avatar asked Dec 21 '25 09:12

Ross


1 Answers

You can use the jQuery UI sortable options items or cancel for this purpose. Docs here: http://jqueryui.com/sortable/#items.

You would add them in a binding like:

<div class="container" data-bind="sortable: { data: tasks, options: { cancel: '.prevent' } }">

or globally like:

ko.bindingHandlers.sortable.options.cancel = ".prevent";

Sample here: http://jsfiddle.net/rniemeyer/2wEX3/

like image 176
RP Niemeyer Avatar answered Dec 23 '25 08:12

RP Niemeyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!