2
votes

I am looking for this since last friday, couldnt find any solution. One thing i thought about and tried several times, was to first build the function, where ALL items in the list, containing that one, which actually should be excluded from being droppable into other lists get the right to be moved within that list, and later building another function, where ALL items get prepared to being also moved into other lists, but the one certain item gets excluded from that.

but it seems, that you cant write two functions for one list with jquery or ís it possible?

anyway, my request actually is described best in the title, while i couldnt get any solution to it till now. Does anybody has an idea how to solve this?

Regards, Maschek

EDIT:

Here is some code:

 $("#tx-sortable2").sortable({    
                               items: \'li:not(.tx-header)\',
                                connectWith: \'#tx-sortable2,#tx-sortable3\',            
                                helper: \'clone\',
                                 opacity: 0.6,

                                 forceHelperSize: true,
                                placeholder: \'tx-highlight\',
                                revert: \'invalid\',
                                update: function() {
                                    var order = $(this).sortable("serialize") + \'&action=bla=blubb\';                                    
                                    $.ajax({
                                         url: \'index.php?bla=blubb\',
                                         type: \'POST\',
                                         data: order,
                                         timeout: 50000,
                                         beforeSend: function() {
                                         $("#tx-response").show();
                                         $("#tx-response").fadeOut(2000);
                                    }
                               });                    
                          }             

In this example all li-items within #tx-sortable2 can be moved to the lists #tx-sortable3 and within the list #tx-sortable2 itself, thats what connectWith means. again, my question is, how do i make a single li-item sortable within its own list (here #tx-sortable2), but prevent it from being dragged into the other list?

2
I don't understand the question - "exclude item from being connected with other lists and being sortable in its own list". Is not clear what you want or what the problem is, eg what does "being connected with" mean ?NimChimpsky

2 Answers

3
votes

You could trigger a cancel event when ever the excluded item is moved to a connected list. Just give the excluded item some special attribute (class).

Something in the lines of.

html

<ul id="tx-sortable2">
    <li>Element2_1</li>
    <li class="excluded">Element2_2</li>
    <li>Element2_3</li>
    <li>Element2_4</li>
</ul>

<ul id="tx-sortable3">
    <li>Element3_1</li>
    <li>Element3_2</li>
    <li>Element3_3</li>
    <li>Element3_4</li>
</ul>

js

$("#tx-sortable2").sortable({
    connectWith: '#tx-sortable3', 
    over: function(){
        if($(ui.item.hasClass('excluded')){
           $(ui.sender).sortable('cancel');
        }
});
1
votes

I think you can use the jQuery UI´s own option called Axis. It specifies the direction in which an item can be moved. So if your other lists are on the right or on the left, you can set the axis option to 'y', so you cannot move them horizontally. Then you would have a list where you can sort the items within THAT list, but you could not connect it with other lists.