The COLGROUP HTML tag is used in tables. This tag is used by diff.module (among others). The proposal here is to add support for this feature to theme_table() so that diff module can get rid of its reimplementation of theme_table(). I think we will find several uses for this, but for I just want the framework to support it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dvessel’s picture

++ I'd like to see this supported. Table data can get really interesting visually with simpler class naming among other things.

moshe weitzman’s picture

Status: Active » Needs review
FileSize
2.14 KB

Here is a patch. This is straight from diff module. Thats god, because this diff code is currently in use on drupal.org and on sites everywhere.

floretan’s picture

I applied the patch and I was able to affect a table with the $cols parameter, but figuring out the proper format was far from easy (even for someone who's familiar with the array structure for the $header and $rows parameters).

The documentation for the $cols parameter should be expanded and provide the same level of detail as the other two. Other than that this patch looks good to me.

moshe weitzman’s picture

agreed. any chance you can write that up, flobruit? i will put it in the patch if you don't want to deal with command line.

Susurrus’s picture

Status: Needs review » Needs work

Because of #3 and #4.

floretan’s picture

Status: Needs work » Needs review
FileSize
3.12 KB

The $cols parameter is actually passing information about COLGROUP elements, so the name of the parameter should be $colgroups. Unlike headers and rows, column groups don't have cells, so that terminology in the code is not accurate.

Here's a patch with the following variable name changes:

$cols  => $colgroups
$col   => $colgroup
$cells => $cols
$cell  => $col

The code logic looks good and hasn't been altered.

The patch also includes a more extensive doxygen documentation with examples. I found it difficult to be clear about the parameter definition without referring to the corresponding HTML elements, so suggestions for better alternatives are welcome.

floretan’s picture

Moshe suggested outside of this issue that this colgroup functionality could be used to indicate the "active" column in sorted tables, so I took some time to investigate this feasibility. The outcome is that using colgroups to indicate the active column would come at the price of other complications:

CSS conflicts
We can use a background color on colgroup and col elements, but the background color of tr elements takes precedence and there is no way to target td elements inside of a specific columns using CSS rules.
The 'span' attribute
When generating th and tr elements, we can use tablesort_cell() to figure out if they are in the active column because we can make the assumption that the 'span' attribute is not used on sortable tables. However, this is not true for colgroup and col elements. We could figure out the active column by parsing the 'span' attributes but this is pretty messy and probably not a valuable addition to the table theme function.
moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Very nice docs, flobruit. Thanks.

I tested and this didn't break any tables. I think thats sufficient for now.

drewish’s picture

subscribing

Dries’s picture

Status: Reviewed & tested by the community » Needs work

* The PHPdoc is wrapped inconsistently. Better to wrap it more or less at the same width/length. Otherwise looks good.

* Tests wouldn't hurt, although it might be difficult to test.

* Can we use colgroups anywhere in core?

floretan’s picture

Status: Needs work » Needs review
FileSize
3.14 KB

* Re-rolled patch and adjusted PHPdoc wrapping.

* Tests would indeed be nice, but how do we test theme functions?

* As mentioned in #7, colgroups cannot be used for the active column of sorted tables. I looked for other places in core where this could be used but didn't find any.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Thanks flobruit. I think we your addressed Dries' questions, and this is RTBC. It applies correctly still.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for fixing the comments, and the clarifications. I've committed this to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

Murz’s picture

Status: Closed (fixed) » Active

At May 23, 2008 I see message "committed this to CVS HEAD", but I didn't see this in Drupal 6.14.
And no changes in api: http://api.drupal.org/api/function/theme_table/6
In which HEAD does this patch committed?

moshe weitzman’s picture

YOu are looking at Drupal6 pages. This is part of Drupal7. See http://api.drupal.org/api/function/theme_table/7

Murz’s picture

Status: Active » Closed (fixed)

Ok, in 7.x-dev I have found it. And last patch applied succesfully on Drupal 6.14.