Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>UPDATED 2012</p> <p><a href="http://so.lucafilosofi.com/jquery-ui-sortable-determining-in-what-order-the-items-are/" rel="nofollow noreferrer"><strong>FULL WORKING DEMO &amp; SOURCE</strong></a></p> <hr> <p>get the index position of the elements try to read this:</p> <blockquote> <ul> <li><a href="https://stackoverflow.com/questions/2442232/getting-the-position-of-the-element-in-a-list-when-its-drag-dropped-ui-sortable/2443081#2443081">Getting the position of the element in a list when it&#39;s drag/dropped (ui.sortable)</a></li> </ul> </blockquote> <p>COOKIE plugin for jquery:</p> <blockquote> <ul> <li><a href="http://plugins.jquery.com/project/cookie" rel="nofollow noreferrer">http://plugins.jquery.com/project/cookie</a></li> </ul> </blockquote> <p><strong>JQUERY:</strong></p> <pre><code> $(function() { //coockie name var LI_POSITION = 'li_position'; $('ul#sortable').sortable({ //observe the update event... update: function(event, ui) { //create the array that hold the positions... var order = []; //loop trought each li... $('#sortable li').each( function(e) { //add each li position to the array... // the +1 is for make it start from 1 instead of 0 order.push( $(this).attr('id') + '=' + ( $(this).index() + 1 ) ); }); // join the array as single variable... var positions = order.join(';') //use the variable as you need! alert( positions ); // $.cookie( LI_POSITION , positions , { expires: 10 }); } }); });​ </code></pre> <p><strong>HTML:</strong></p> <pre><code>&lt;ul id="sortable"&gt; &lt;li id="id_1"&gt; Item 1 &lt;/li&gt; &lt;li id="id_2"&gt; Item 2 &lt;/li&gt; &lt;li id="id_3"&gt; Item 3 &lt;/li&gt; &lt;li id="id_4"&gt; Item 4 &lt;/li&gt; &lt;li id="id_5"&gt; Item 5 &lt;/li&gt; &lt;/ul&gt; </code></pre> <p><strong>PHP:</strong></p> <p>this is just an example but you got the idea: you may want use a database instead and use AJAX for get back the lis:</p> <pre><code>&lt;?php //check if cookie is set.. if ( isset( $_COOKIE['li_position'] ) ) { //explode the cockie by ";"... $lis = explode( ';' , $_COOKIE['li_position'] ); // loop for each "id_#=#" ... foreach ( $lis as $key =&gt; $val ) { //explode each value found by "="... $pos = explode( '=' , $val ); //format the result into li... $li .= '&lt;li id="'.$pos[0].'" &gt;'.$pos[1].'&lt;/li&gt;'; } //display it echo $li; // use this for delete the cookie! // setcookie( 'li_position' , null ); } else { // no cookie available display default set of lis echo ' &lt;li id="id_1"&gt; Fuji &lt;/li&gt; &lt;li id="id_2"&gt; Golden &lt;/li&gt; &lt;li id="id_3"&gt; Gala &lt;/li&gt; &lt;li id="id_4"&gt; William &lt;/li&gt; &lt;li id="id_5"&gt; Jordan &lt;/li&gt; '; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload