Reputation: 35268
Is there a way to disable the drag and drop when using sortable in knockout js. I have a square grid with 5*5 squares inside it. I want to disable drag and drop for some squares not all.. How can this be done? any suggestion..
Upvotes: 2
Views: 1854
Reputation: 139758
There is support for this in the jQuery UI sortable this on the demo page.
You just need to add a special class to your non sortable items (e.g with the css
binding) then you need use the cancel option where you can set this non sortable class name.
And you can specify options for the sortable
binding with the options
parameter:
data-bind="sortable: {data: items, options: { cancel: '.no-sort' }}"
A simple demo HTML:
<ul data-bind="sortable: {data: items, options: { cancel: '.no-sort'}}">
<li data-bind="text: name, css: { 'no-sort': disabled}"></li>
</ul>
And the JS:
var vm = {
items: [
{name: 'name1', disabled: false},
{name: 'name2', disabled: false},
{name: 'name3', disabled: true},
{name: 'name4', disabled: false},
{name: 'name5', disabled: true}
]
}
ko.applyBindings(vm);
Demo JSFiddle.
Upvotes: 6