title: Default order with jQuery UI Sortable
body: <p>I have the following issue. I want to do the next thing. In the webpage I'm developing, when a user is logged, he has to arrange some variables and I need to save the order he arranged them. With this code I could get the order value of each item setting it in a hidden form input so when the user press "save" those valued are saved within a MySQL database. Until here it works fine:</p>
  
  <pre><code>$(document).ready(function() { $( function() {
      $( "#sortable" ).sortable( {
      placeholder: "ui-state-highlight",
      helper: 'clone',
      sort: function(e, ui) {
          $(ui.placeholder).html(Number($("#sortable &gt; li:visible").index(ui.placeholder)) + 1);
      },
      update: function(event, ui) {
          var $lis = $(this).children('li');
          $lis.each(function() {
              var $li = $(this);
              var newVal = $(this).index() + 1;
              // $(this).children('.sortable-number').html(newVal);
              $(this).children('input').val(newVal);
  
          });
      } }
        );
      $( "#sortable" ).disableSelection();
         } ); } );
  </code></pre>
  
  <p>This is the output from PHP (each item look like this):</p>
  
  <pre><code>&lt;li class="ui-state-default bookred"&gt;&lt;input type="hidden" name="grammar1" value="&lt;?php echo $grammar1 ?&gt;"&gt;&lt;a data-fancybox="" data-src="exercises/grammar-pronomen.php" href="javascript:;"&gt;&lt;i class="fa fa-eye" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;a href="#" class="delete"&gt;&lt;i class="fa fa-trash" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt; &lt;span class="ui-icon ui-icon-arrowthick-2-n-s"&gt;&lt;/span&gt;Pronomen&lt;/li&gt;
  </code></pre>
  
  <p>The problem comes when the user refreshes the webpage. The order he chose arranging the elements are not being respected. Getting the values from MySQL is not a problem, the problem is to set those values within the UI in order to get the items arranged as the user did so.</p>
  
  <p>Thanks for your help. </p>