How to create a drag & drop sorting interface programmatically? If you have seen the Views module, there is "sorting criteria", where we add fields and then rearrange fields to set the priority. In order to rearrange, we click on "rearrange" link and all fields get a draggable UI so that we can move it up or down to set sorting priority.

How can I do this thing exactly programmatically?
Here is a drupal_add_tabledrag function using which you can add draggable functionality programmatically.


  Assists in adding the tableDrag JavaScript behavior to a themed table.
  
  Draggable tables should be used wherever an outline or list of
  sortable items needs to be arranged by an end-user. Draggable tables
  are very flexible and can manipulate the value of form elements placed
  within individual columns.


See this blog for example. You may need to imprement theme function.

$element = $vars['element'];
drupal_add_tabledrag('sample_table', 'order', 'sibling', 'item-row-weight');

$header = array(
  'label' =&gt; t('Attribute'), 
  'checkbox' =&gt; t('Enabled/disabled'),
  'weight' =&gt; t('Weight'),
);