Nishima
Nishima

Reputation:

jquery disable sortable

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();

}

Upvotes: 0

Views: 13399

Answers (2)

user3038781
user3038781

Reputation: 11

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?

Upvotes: 1

Vitaly Dyatlov
Vitaly Dyatlov

Reputation: 1872

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..

Upvotes: 7

Related Questions