tableheader.js is always included and applied to your theme_table(), whether you like it or not!

There is no way to avoid having the sticky tableheaders applied without overriding some theme functions, or avoiding the use of theme_table(). The use case could be wanting to use a different technique for table headers, a fancy jquery-based table package (datatable, yui_datatable, etc), or simply performance reasons if you know this not going to be required.

Currently, this can only be done by unsetting tableheader.js in a preprocess_page() function, or by overriding theme_table, which seems a little extreme. I believe the sticky table headers should be optional to begin with.

I propose adding a conditional check against the class 'sticky-disabled' in theme_table before applying the tableheader.js logic. In this way specific tables could have this functionality removed, but in all other cases the behavior would remain as it is now.

For example, a call to theme table without tableheader would look like:

 theme('table', $header, $rows, array('class' => 'sticky-disabled'));

this applies to HEAD and D6 branches, I will provide a patch against HEAD shortly unless there is a better idea :)

Comments

kscheirer’s picture

Status: Needs work » Needs review
StatusFileSize
new1.08 KB

patch against HEAD, and added some detail to the docs

Status: Needs review » Needs work

The last submitted patch failed testing.

kscheirer’s picture

Status: Needs work » Needs review
StatusFileSize
new1.11 KB

doh! added a check to make sure $attributes['class'] is set to prevent strpos from throwing notices

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

I have needed this in the past. I like the implementation.

kscheirer’s picture

StatusFileSize
new1.11 KB

hmm, when there's no $attributes['class'] set, the isset() fails and sticky headers don't get applied. oops.

this patch has the desired effect, leaves table behavior unchanged unless the class 'sticky-disabled' is applied.

also this brings up the point that there's no simpletest for checking misc/tableheader.js - is that something we want to do?

kscheirer’s picture

Status: Reviewed & tested by the community » Needs review
mr.baileys’s picture

+1 for getting this implemented.

Personally, I'm not a big fan of using the $attributes array for this: IMHO, the $attributes array is just a bunch of attributes that need to be passed through to the tag being rendered, and the theme function(s) should not use elements of the array in any kind of logic. I couldn't find a similar use of the $attributes array in theme.inc. I also find it counter-intuitive to have to add a class in order to remove functionality.

Is it an option to change the function signature to something like:

function theme_table($header, $rows, $attributes = array(), $caption = NULL, $colgroups = array(), $sticky = TRUE) {

...or would that make the signature overly long?

also this brings up the point that there's no simpletest for checking misc/tableheader.js - is that something we want to do?

I'd say yes. If this functionality is added, we should also add a test for it.

Also, I'm not sure that this is a bug, it feels more like a feature request to me.

dave reid’s picture

+1 to a parameter and not using the attributes hack. We can at least make a basic test that if $sticky = FALSE, there is no instance of 'tableheader.js' in the page request source code with a table.

kscheirer’s picture

Adding a parameter is a cleaner way to do it from a code point of view. But it would also put us up to 6 parameters, leading to

  theme('table', $header, $rows, array(), NULL, array(), TRUE) {

to turn off tableheader.js. Looks suspiciously like the old l() function, and the whole thing should probably take an associative array of arguments instead. Adding the single parameter is very easy of course, but rewriting the function arguments would be a decent sized patch.

@mr.bailey's: its a bug in the sense that Drupal does not normally force advanced UI elements in core. Having a sensible default is good, but there does need to be a way to disable it when requested.

senpai’s picture

Status: Needs review » Needs work

And I'd like to point out that the norm is to have sticky headers, and the *rare* abnormality would be to turn them off for a table that's being generated by a custom module or something. I certainly don't like the presence of a sixth param for theme_table, but it seems to me that having it default to true would mean that 98+ percent of the population would go happily along their merry way, never needing or calling the function with that last parameter.

The remaining 1+ percent of us who need to turn off sticky headers would then have the option to do so, and if you did need to for some reason, how many times would you have to write a sticky-less theme_table() function in a single site or module? Once?

Karl, let's go with the additional param on this one. I've looked into the simpletests for this, and having to test for the presence of and absence of a 'sticky-enabled', 'sticky-disabled', and so on is far uglier that checking for the presence of $sticky_header = TRUE or $sticky_header = FALSE.

AND THEN! There's the current Designer Themer push (#D4D) that is trying to remove all un-necessary CSS classes from core, and this patch as it stands would require developers to pass a "useless" CSS class all the way through to the browser just to remove a usability feature for one HTML table. Ungood?

kscheirer’s picture

ok, extra param it is. I'll post something as soon as I have a chance.

kscheirer’s picture

Status: Needs work » Needs review
StatusFileSize
new2.81 KB

ok, added the extra param to theme_table(), 99% of the time no one will need to use it. Updated the function docs.

Added a unit simpletest to check that tableheader.js and the class 'sticky-enabled' are handled properly when then flag is set or not. Had to create a new theme.test file in modules/simpletests/tests/ unless there's a better place to put these?

Possible additional tests:

  • when there are no table headers, check to make sure tableheader.js+class is not added.
  • check 'admin/build/permissions' page to make sure tableheader.js is applied here (browser test, instead of just unit).

I don't write a lot of tests, so any feedback is appreciated. Thanks!

Status: Needs review » Needs work

The last submitted patch failed testing.

kscheirer’s picture

Assigned: kscheirer » Unassigned
Status: Needs work » Closed (duplicate)

so this issue is a duplicate :( I did searched before creating, but did not find http://drupal.org/node/336475

on the plus side, that issue arrived at exactly the same code changes as specified here, just no tests included.

So I'm marking this as a duplicate, and I'll add the tests to a patch in the other issue.

johnalbin’s picture

Issue tags: -Usability, -theming

cleaning up issue tags

jmmec’s picture

Hi,

I'm running 6.13 with the fix mentioned in this thread, however it seems that the sticky-header (or some side-effect of it) is still being applied, even if I disable it via:

theme_table(blah, blah, array('class' => 'sticky-disabled'));

Should the code in "theme.inc" be something like this:

    $attributes['class'] = empty($attributes['class']) ? 'sticky-enabled' : ($attributes['class']);

instead of this:

    $attributes['class'] = empty($attributes['class']) ? 'sticky-enabled' : ($attributes['class'] .' sticky-enabled');

I need to do more investigation, but I have more details at the following location in case anyone has any insight: http://drupal.org/node/577596

Regards

kayograco’s picture

Status: Closed (duplicate) » Needs review

#5: drupal-415024_2.patch queued for re-testing.

kscheirer’s picture

Status: Needs review » Closed (duplicate)

why needs review? this issue is a duplicate, and all the code was already committed in #336475: simpletests for sticky tableheaders.