Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Sortable set manually a position

How can I manually set a position with some code?

Ok

Ive got some div with the sortable() behavour :

<div class="sort" id="a"></div>
<div class="sort" id="b"></div>
<div class="sort" id="c"></div>
<div class="sort" id="d"></div>
<div class="sort" id="e"></div>

I want to set manually(click on a button) the order with sortable jquery ui behavor with some code To get something like this

<div class="sort" id="b"></div>
<div class="sort" id="c"></div>
<div class="sort" id="e"></div>
<div class="sort" id="d"></div>
<div class="sort" id="a"></div>

Any idea

like image 506
SoCkEt7 Avatar asked Apr 02 '12 18:04

SoCkEt7


1 Answers

There isn't a built-in option to reorder the elements, however using jQuery you can reorder the elements like this:

$("#sortable").sortable().disableSelection();
$("#sortable li:eq(3)").insertAfter($("#sortable li:eq(4)"));
$("#sortable li:eq(0)").insertAfter($("#sortable li:eq(4)"));

jsFiddle example. Original order: A, B, C, D, E. New order: B, C, E, D, A.

like image 103
j08691 Avatar answered Oct 28 '22 22:10

j08691