I have a drupal 7 view, consists of table. I need to add sort symbol (both asc and desc) in view header by default if no sorting applied.

I tried with altering views-view-table.tpl.php file, and added asc, desc images for each header.

But I need proper solution, Is there any hook there to alter the table headers?

  • you can add class to the table. Then you can do CSS Sep 13, 2017 at 10:11

2 Answers 2


Implement theme_tablesort_indicator(). Please replace your theme name with example

function example_tablesort_indicator($variables) {
  $style = $variables['style'];
  $theme_path = drupal_get_path('theme', 'example');
  if ($style == 'asc') {
    return theme('image', array('path' => $theme_path . '/images/arrow-asc.png', 'alt' => t('sort ascending'), 'width' => 13, 'height' => 13, 'title' => t('sort ascending')));
  else {
    return theme('image', array('path' => $theme_path . '/images/arrow-desc.png', 'alt' => t('sort descending'), 'width' => 13, 'height' => 13, 'title' => t('sort descending')));

I think your best bet without a lot of theming and template overrides, preprocessing and some JS is to use jquery TableSorter:

What you have linked to is actually an Angular based front end. TableSorter is the next closest thing without being Angular JS.

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.