Creating a sortable field I have a custom field declared and I am trying to make it sortable. The field holds date values already formatted ie: 06/10/12. How could I make this sortable? I thought this code would work but the header on the table doesn't become hyper linked even. 

     function uc_order_views_data() {
      $data['uc_orders']['data'] = array(
        'group' =&gt; t('Order') . ':data',
        'title' =&gt; t('Ship Date'),
        'help' =&gt; t('The date to ship the order.'),
        'field' =&gt; array(
        'handler' =&gt;'uc_order_handler_field_ship_date',
          'click sortable' =&gt; TRUE,
         ),
         'sort' =&gt; array(
           'handler' =&gt; 'views_handler_sort',
         ),
         'filter' =&gt; array(
           'handler' =&gt; 'views_handler_filter_string',
         ),
      );
     }


I do have the ability to send through a UNIX epoch timestamp instead if that would help me make this sortable so long as I can sort by the epoch but render it as a formatted date.
The fact that this is an extension of ubercart bears no factor on the result. Treat this question as if it were just a simple implementation of the views module, which in essence it is.
I finally figured out the answer. Only took me a week.

Under the view settings there is a "Format" option, and beneath that there is a "Settings" link. Upon clicking there are options to make your new fields sort-able or not to the user. Adding 'click sortable' =&gt; TRUE just exposes that radio button!

Good grief that was causing me some headaches! I was beating myself up on the code when it was a UI setting withing Drupal.

Something else to consider is the actual sorting. There are many different handlers for sorting fields. This particular field is a date. In order for this to work, the date needs to be stored as a UNIX time epoch. There are flags that I did not pass that can allow you to choose the granularity of the sort, (seconds, minutes, days, months, years).

This is what my code ended up looking like to make the date sort actually work as expected. When I stored the date as a UNIX time epoch.

/**
 * Implements hook_views_data().
 */
function uc_order_views_data() {
  $data['uc_orders']['data'] = array(
    'group' =&gt; t('Order:data'),
    'title' =&gt; t('Ship Date'),
    'help' =&gt; t('The date to ship the order.'),
    'field' =&gt; array(
      'handler' =&gt;'uc_order_handler_field_ship_date',
      'click sortable' =&gt; TRUE,
     ),
     'sort' =&gt; array(
       'handler' =&gt; 'views_handler_sort_date',
     ),
     'filter' =&gt; array(
       'handler' =&gt; 'views_handler_filter_date',
     ),
  );
}


Now, lets take a look at the uc_order_handler_field_ship_date handler. You want to be sure that if you are not using the standard sort handler, that you extend the proper handler. If this date was not buried within some serialized data, I wouldn't even need this class and the default views handler would be sufficient.

class uc_order_handler_field_ship_date extends views_handler_field_date {
  /**
   * Overrides views_handler_field_date::render().
   */
  function render($values) {
    $data = unserialize($values-&gt;uc_orders_data);
    if (isset($data['fedex_calendar_ship_date'])) {
      $date = $data['fedex_calendar_ship_date'];
    }
    else {
      $date = "-";
    }
    return date('n/j/Y',$date);
  }
}


For more information on all of the sort handlers available see:
http://api.drupal.org/api/views/handlers%21views_handler_sort.inc/class/views_handler_sort/7