This module provides an additional sort for FieldAPI fields, which sorts by whether the field is empty or not. This allows empty (i.e. NULL) values in fields to be sorted last.

This module has for motivation the following problem:

  • You have a view listing nodes.
  • These nodes have a field on them, 'field_foo'.
  • You want to sort the view by this field, ascending.
  • Some nodes have nothing in this field.
  • Because of the way SQL sorting works, the nodes with no value are at the top of the list.

A common use case for this is using Draggable Views and a numeric weight field to order nodes. New nodes will receive a NULL value in the field, and so will appear at the top without this module's sort handler.

In combination with the regular sort, this can be used to place empty values at the end of the ascending results, or at the top of descending results.

Project Information