Is it possible to disable sticky table headers?
With enabled sticky table headers it really hurts to browse the modules-admin-page so I'd like to disable. I searched drupal.org and the web but everything I can find is about ENabling sticky table headers.

Comments

Sabino’s picture

Adding the following code to template.php disables sticky table headers.

function phptemplate_preprocess_page(&$vars) {
  $vars['tabs2'] = menu_secondary_local_tasks();
 
  // Hook into color.module
  if (module_exists('color')) {
    _color_page_alter($vars);
  }
 
  // remove sticky table headers
  $js = drupal_add_js();
  unset($js['module']['misc/tableheader.js']);
  $vars['scripts'] = drupal_get_js('header', $js);
}
sapark’s picture

Thanks!

sspraggs’s picture

Alternatively, if you want to disable the sticky table header on a per table basis - instead of site wide, you can do the following.

1. Add an id or class to your table, e.g.
theme('table', $header, $rows, array('class' => 'no-sticky'));

2. Add JS to the page that will add the tableHeader-processed class to your table before the JS in tableheader.js has a chance to run. This will result in the table being skipped when Drupal.behaviors.tableHeader fires. e.g.
drupal_add_js('$("table.no-sticky thead").addClass("tableHeader-processed");', 'inline');

Note, the JS should be after the table is already on the page since the table must be evaluated by the browser before the JS runs. It's not sufficient to do on document ready since Drupal will process table headers first.

In reality, there needs to be a patch to theme_table that gives developers the option to turn it off.

mmilano’s picture

nice solution. i added 'footer' for the scope to force the js to the bottom.

drupal_add_js('$("table.no-sticky thead").addClass("tableHeader-processed");', 'inline', 'footer');

torgosPizza’s picture

This worked for me, thanks!

Remember that you'll need to change table.no-sticky to be table.CLASS (where CLASS is the class of the table you want to affect). You could also use table#TABLEID to target one specific table.

Have I helped you? Consider buying me a beer.

kayograco’s picture

Hmmm... just copy paste, nothing happen.

PS: I swapped between themes and it worked in all the tables except for the modules one, weird. Anyway, thank's a lot, this is what I was looking for.

thedavidmeister’s picture

As well as checking individual tables, tableheader.js also checks to see if the body has a class of tableHeader-processed so something like this should work too (this code is the D6 version):

  /**
    * Implements MODULE_preprocess_page().
    */
  function MODULE_preprocess_page(&$vars) {
    $vars['attr']['class'] .= ' tableHeader-processed';
  }
possible181’s picture

Hey that worked for me...

thanks.

i have been going like crazy to find a remedy for days..
i also posted my question here http://drupal.org/node/896996
but no one answered because i didn't know what a sticky table was until today, when i created a view and went to formating options and saw the "Enable Drupal style "sticky" table headers (Javascript)" checkbox and my my head clicked!

regards
Baloch

TomiMikola’s picture

Yet another method is to overwrite the Drupal.behaviors.tableHeader:

function mymodulename_init() {
  //Disable sticky table headers if conditions met
  if (variable_get('mymodulename_disable_sticky_js_headers', FALSE)) {
    drupal_add_js('Drupal.behaviors.tableHeader = function(){};', 'inline', 'footer');
  }
}

function mymodulename_settings_form() {
  $form = array();
  $form['mymodulename_disable_sticky_js_headers'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disable sticky table headers'),
    '#default_value' => variable_get('mymodulename_disable_sticky_js_headers', FALSE),
    );
  return system_settings_form($form);
}

function mymodulename_menu() {
  $items['admin/settings/mymodulename'] = array(
    'title' => t('My Module Name'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('mymodulename_settings_form'),
    'access arguments' => array('administer site configuration'),
  );
  return $items;
}

You can imagine how the settings could expanded to include some other options like list of matched paths etc. But as said in previous comments, these all are sort of hacks anyway. Should be handled by the core.

OliverColeman’s picture

Another option is to modify the themed output HTML in your theme function to add the "tableHeader-processed" class to the thead element, eg:

$table = theme('table', $header, $rows);
$table = str_replace('<thead>', '<thead class="tableHeader-processed">', $table);

This won't work if the thead element has any other attributes (but it also won't break horribly if it does). The core theme_table function doesn't add any attributes to the thead element so unless that has been overridden the above example should be fine.

rooby’s picture

If you have control over the code that is calling theme('table') you can pass in a sticky variable.

<?php
$table = theme('table', array('header' => $header, 'rows' => $rows, 'sticky' => FALSE));
?>
dizarter’s picture

True for D7, not applicable to D6, since it only checks if there is a header row.

wOOge’s picture

Here's how to do it in D7 :

Place this code in your theme's template.php

function THEME_NAME_js_alter(&$js) {
    unset($js['misc/tableheader.js']);
}

Replace THEME_NAME with the name of your theme.
The don't forget to clean your caches!!

--
wOOge | adrianjean.ca

Anonymous’s picture

+1

Jawi’s picture

+1

Practice what you preach >> www.jawi-online.nl >> Full service internet bureau >>

limecake’s picture

Well done, works like a charm!