0

I want to disable sorting of source_element .how can i do so?

function dropMembers(){
        $("ul.present").sortable({
            connectWith: 'ul',
            containment: 'window',
            items: 'li:not(.notSortable)'
        });

        $("ul.usrlist").sortable({
            connectWith: 'ul',
            dropOnEmpty: true,
            containment: 'window',
            update: function(event, ui) {
                //Element ready to be dropped to new place
                   source_element = $(ui.item).attr("id");
                   alert(source_element);
                   source_element1=source_element.split('_');
                   alert(source_element1);
                   if(source_element[1]==GLOBAL_MY_ID){
                       // I want to disable sorting of source_element here
                   }
                   // here is your selected item  }
            }
//             sort: function(event, ui) {
//             var usr_result=$("ul.usr").sortable('toArray');
//             //alert(ui.sortable);
//            }
        });

        $("#MAIN_USER_LIST,#USER_PRESENT_LIST").disableSelection();

}

2 Answers 2

7

In your example with code of my prevous answer to disable sorting use

$(ui.sender).sortable('cancel');

But I think, for disable movement better is prevent movement in start event and disable it as:

$(this).sortable('cancel');

P.S.: You create new question with my code without mark my answer as accepted. Dont understand your behavior..

Sign up to request clarification or add additional context in comments.

Comments

1

Had a heck of a time on this one..

$(ui.sender).sortable('cancel') seems to revert to their previous location, but leaves it sortable..

To remove sorting (and allow editing again), I used this code:

$('.sortable').sortable('disable'); 
$('.sortable').disableSelection('disabled'); 
$('.sortable').unbind('click');
$('.sortable').unbind('mousedown');
$('.sortable').unbind('mouseup');
$('.sortable').unbind('selectstart');

Change .sortable to your element's designator. I did it by class for multiple. These were the 4 events I found created by the sort routine. You can reactivate the sort by the original command.

very handy, eh?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.