I have made a custom views field handler by the following instruction:


The problem is that, I cannot sort the values of the created pseudo field in view. I know the reason is that my pseudo field basically doesn't exist in query of the corresponding view, and cannot exist there as it doesn't exist in any tables and it's just a computed field for that view.

Any ideas about making this field sortable?

  • Even I tried to add a sort_handler to it. Even custom sort handler didn't work. When I click on title of field in the view to sort, it only returns an empty view.
    – Ehsan
    Mar 2, 2015 at 15:26
  • I could not explain whole process, so I decided to put the reference link in the post, as it's a nice tutorial for the people who are looking to do the same thing, without sorting ability.
    – Ehsan
    Mar 2, 2015 at 15:28

1 Answer 1


you should pass 'click sortable' => TRUE parameter together with 'handler':

  'field' => array(
    'handler' => 'views_handler_my_custom_field',
    'click sortable' => TRUE,

Then you can override click_sort($order) in your views_handler_my_custom_field class, e.g. you can explicitly override the 'orderby' array of query object:

function click_sort($order) {
  $this->query->orderby[] = array(
    'field' => '...', // here may be a field, or some SQL clause e.g. FIELD(str, str1, ...)
    'direction' => strtoupper($order),

See also click_sort($order) in views_handler_field class.

HTH, Alexander

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.