Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if list is sortable?

How to check if a specific list is sortable? Like $('#list').is(':sortable')... ?

If we will use

if ($('#list').sortable()) 

then the list will be made sortable again and not check if actually it is sortable.

like image 424
user1502679 Avatar asked Jul 22 '12 11:07

user1502679


4 Answers

If the list is already sortable, then it should have class ui-sortable.

You could use if ($('#list').hasClass('ui-sortable')) to check it.

like image 184
xdazz Avatar answered Nov 05 '22 01:11

xdazz


I just found out, with the data-interface it is working too:

if ($( '#sortable' ).data( 'sortable' )) {
    // sortable instance exists
}
like image 36
jebbie Avatar answered Nov 05 '22 00:11

jebbie


There was a change in jQuery Version after 2012, so now you can write:

if ($( '#sortable' ).data( 'ui-sortable' )) {
    // sortable instance exists
}

or

if ($( '#sortable' ).is(':ui-sortable')) {
    // sortable instance exists
}
like image 7
Frank Avatar answered Nov 05 '22 02:11

Frank


When applying Sorting, just add a dummy class to that element like this,

$( "#sortable" ).sortable();
$( "#sortable" ).addClass("antguider");

then, If you want to check the element is sortable then check like this,

if($( "#sortable" ).hasClass("antguider")){
    alert("Already Sort Applied");
}
like image 2
Jayamurugan Avatar answered Nov 05 '22 01:11

Jayamurugan