Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think what you want to do is have an ordered list of items (1. Item 1, 2. Item 2, 3. Item 3) and then when one item is moved you want to renumber the list, right? So if 2 is moved below three, you would want the text to say something like 1. Item 1, 2. Item 3, 3. Item 2. If I'm correct with that, your code would look something like this. First, here's what your HTML would need to look like.</p> <pre><code>&lt;ul id="yourSortableListID"&gt; &lt;li class="renumberMe"&gt;&lt;span class="list_num"&gt;&lt;/span&gt; Item 1&lt;/li&gt; &lt;li class="renumberMe"&gt;&lt;span class="list_num"&gt;&lt;/span&gt; Item 2&lt;/li&gt; &lt;li class="renumberMe"&gt;&lt;span class="list_num"&gt;&lt;/span&gt; Item 3&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Your JavaScript would look something like this:</p> <pre><code>function renumberListItems() { i = 1; $(".renumberMe").each( function() { $(".list_num", this).text(i + "."); i++; }); } // we don't want to add the sortable until the dom is ready $(document).ready(function() { renumberListItems(); $("#yourSortableListID").sortable({ stop: function(event, ui) {renumberListItems();} }); }); </code></pre> <p>renumberListItems() goes through each of the li items, then finds the list_num items within it, and just updates the text using <code>i</code>'s value so that the list is renumbered. We do this using the <code>stop</code> event provided with sortables (more info under the Events tab on <a href="http://jqueryui.com/demos/sortable/" rel="nofollow noreferrer">this page</a>), which calls whatever function you give it whenever the user has moved an item and releases the mouse.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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