connectClass on individual item

42 Views Asked by At

I am trying to setup knockout to restrict which lists items can be dragged into. I have been looking at the connectClass functionality but I'm not sure it can do quite what I need.

My application has a series of sortable lists, the user populates these lists my dragging items from another list of 'unassigned items' (List E in the example). The number of lists will vary but they are always one of two different types. Therefore for simplicity, I will say there is only two of each type:

5 lists (A to E)

  • List A: items can go to list B or list E
  • List B: items can go to list A or list E
  • List C: items can go to list D or list E
  • List D: items can go to list C or list E
  • List E: some items can go to A or B, some can go to C or D

I think what I need it to be able to effectively specific the 'connectClass' value on each item in List E (rather than the whole list). Is there a way to do this?

1

There are 1 best solutions below

0
Caffeine Junkie On

Thank you for the tip, figured out you can do it with the "beforeMove" event:

ko.bindingHandlers.sortable.beforeMove = function (args) {

    if (args.targetParent.ListE == false) //otherwise always ok
    {
        if (args.targetParent.Something != args.item.Something) { //this line evaluates if it is ok to drop the item
            args.cancelDrop = true; //if not, cancel the drop
        }
    }
};