Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The jQuery UI <a href="http://api.jqueryui.com/sortable/" rel="noreferrer"><code>sortable</code></a> feature includes a <a href="http://api.jqueryui.com/sortable/#method-serialize" rel="noreferrer"><code>serialize</code> method</a> to do this. It's quite simple, really. Here's a quick example that sends the data to the specified URL as soon as an element has changes position.</p> <pre><code>$('#element').sortable({ axis: 'y', update: function (event, ui) { var data = $(this).sortable('serialize'); // POST to server using $.post or $.ajax $.ajax({ data: data, type: 'POST', url: '/your/url/here' }); } }); </code></pre> <p>What this does is that it creates an array of the elements using the elements <code>id</code>. So, I usually do something like this:</p> <pre><code>&lt;ul id="sortable"&gt; &lt;li id="item-1"&gt;&lt;/li&gt; &lt;li id="item-2"&gt;&lt;/li&gt; ... &lt;/ul&gt; </code></pre> <p>When you use the <code>serialize</code> option, it will create a POST query string like this: <code>item[]=1&amp;item[]=2</code> etc. So if you make use - for example - your database IDs in the <code>id</code> attribute, you can then simply iterate through the POSTed array and update the elements' positions accordingly.</p> <p>For example, in PHP:</p> <pre><code>$i = 0; foreach ($_POST['item'] as $value) { // Execute statement: // UPDATE [Table] SET [Position] = $i WHERE [EntityId] = $value $i++; } </code></pre> <p><a href="http://jsfiddle.net/ryTsN/" rel="noreferrer">Example on jsFiddle.</a></p>
    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.
    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