Index: handlers/views_handler_sort.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/views/handlers/views_handler_sort.inc,v
retrieving revision 1.1
diff -u -r1.1 views_handler_sort.inc
--- handlers/views_handler_sort.inc	3 Sep 2008 19:21:28 -0000	1.1
+++ handlers/views_handler_sort.inc	22 Mar 2009 06:11:53 -0000
@@ -15,6 +15,12 @@
    */
   function query() {
     $this->ensure_my_table();
+
+    // Add an extra field, and put an order by on that field before our actual order by for the empty/null ordering.
+    $field_alias = $this->table_alias .'_'. $this->real_field .'__isnull';
+    $real_field = "$this->table_alias.$this->real_field";
+    $this->query->add_orderby(NULL, "($real_field IS NULL OR $real_field = '')", ($this->options['empty_order_last'] ? 'ASC' : 'DESC'), $field_alias);
+
     // Add the field.
     $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']);
   }
@@ -23,6 +29,7 @@
     $options = parent::option_definition();
 
     $options['order'] = array('default' => 'ASC');
+    $options['empty_order_last'] = array('default' => FALSE);
 
     return $options;
   }
@@ -55,6 +62,12 @@
       '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')),
       '#default_value' => $this->options['order'],
     );
+    $form['empty_order_last'] = array(
+      '#type' => 'checkbox',
+      '#default_value' => $this->options['empty_order_last'],
+      '#title' => t('Empty values order last'),
+      '#description' => t('This allows you to change whether empty/null values appear first in the list (default) or last (checked).'),
+    );
   }
 }
 
