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.
If the list is already sortable, then it should have class ui-sortable
.
You could use if ($('#list').hasClass('ui-sortable'))
to check it.
I just found out, with the data-interface it is working too:
if ($( '#sortable' ).data( 'sortable' )) {
// sortable instance exists
}
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
}
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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With