April 24, 2012

Jquery sortable, how to disable drag and drop

Question by Meg Lepett

<ul id="box">
<li id="1">1</li>
<li id="2">2</li>
</ul>



$("#box").sortable({ update: function() {
    var order = $("#box").sortable("serialize");
    alert(order);
  }
});                                         

I would like to control the order by pressing buttons, and disable the drag and drop.
Everything works great but i could not figure out how to disable the drag and drop but still remain this list sortable?

Edit –

Ok now i start to understand this. I do not need to use sortable at all.
How to get the same result in order variable without using sortable?

Answer by Starx

On that case, you don’t need sortable at all. Just use .append() and .prepend() to shift the position.

$("#link-left").click(function() {
   $("#placetoshift").append($("#thesortablediv"));
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!