Comments

rodych’s picture

Category: feature » bug
StatusFileSize
new849 bytes

I have the same problem, to fix it I add to the theme the attached file.
But I think hide blank table headers must be in the views core.

dawehner’s picture

Status: Active » Needs work

Please provide a real patch with proper codestyle.

mototribe’s picture

creating a template override is a lot of work to just hide the table header ;-) You could do it quickly with some css.

I noticed the following (which might help fix the bug?).
When show a fieldA and turn the label off it shows the empty header with dark background.
Now I add another fieldB right before field A and turn the label off, exclude it from display and
in the table settings have fieldA show in the same column as fieldB.
The result is that the table header isn't shown.

Now I try to use the same trick on the first field. I insert a field before it, turn the label off and exclude
it from display. In the preview the header is gone. But after saving I get a bunch of errors:

Notice: Undefined index: header in template_preprocess_views_view_table() (line 571 of /Users/uwe/Sites/mototribe03/sites/all/modules/views/theme/theme.inc).
Notice: Undefined variable: header in include() (line 26 of /Users/uwe/Sites/mototribe03/sites/all/modules/views/theme/views-view-table.tpl.php).
Warning: Invalid argument supplied for foreach() in include() (line 26 of /Users/uwe/Sites/mototribe03/sites/all/modules/views/theme/views-view-table.tpl.php).
JamesAn’s picture

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

The code changes in #1309026-1: Don't render table header if all field labels are empty work, but I think it'd be more appropriate to put that logic in the preprocess function (and marginally more efficient since the logic can be embedded in the existing loop through all fields).

The attached patch introduces a theme variable, header_empty, that's set to TRUE if all labels are empty strings and FALSE otherwise. The template can simply check this variable before creating the thead element.

JamesAn’s picture

Title: hide tabel header if no label is hidden » Don't render table header if all field labels are empty

We're actually not rendering or omitting the thead element, rather than just hiding it.

JamesAn’s picture

Version: 7.x-3.0-rc1 » 7.x-3.0-rc3

My patch in #1309026-4: Don't render table header if all field labels are empty is actually made against 7.x-3.0-rc3.

zilverdistel’s picture

I made a simpler patch (against 7.3-3.x-dev) which should solves this, without introducing a new variable. Aditionnally, it makes the notices and warnings disappear.

zilverdistel’s picture

removed the tag, (thought it was a title field for the comment)

dawehner’s picture

Status: Needs review » Needs work
+++ b/theme/views-view-table.tpl.phpundefined
@@ -21,6 +21,7 @@
   <thead>
     <tr>
       <?php foreach ($header as $field => $label): ?>
@@ -30,6 +31,7 @@

@@ -30,6 +31,7 @@
       <?php endforeach; ?>
     </tr>
   </thead>

Please add some intentation

zilverdistel’s picture

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

Tnx for the quick review! Added some indentation.

dawehner’s picture

Version: 7.x-3.0-rc3 » 6.x-3.x-dev
Status: Needs review » Patch (to be ported)

Great looks perfect now, so committed to 7.x-3.x

It's probably helpful to backport this change

zilverdistel’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.38 KB

Voila .. backported to 6.x-3.x.

dawehner’s picture

Status: Needs review » Fixed

Thanks! Committed to 6.x-3.x

Status: Fixed » Closed (fixed)

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

jgpippin’s picture

I think the point of doing it as a tpl.php was not to have to use a patch. Personally, I prefer that approach.

dmitriy.trt’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new872 bytes

Checked 7.x-3.2 and it doesn't work. Views still render table header with empty cells because $header variable is not empty even when all labels are disabled. Quick fix is to check filtered header array instead of original.

dawehner’s picture

Status: Needs review » Needs work
+++ b/theme/views-view-table.tpl.phpundefined
@@ -21,7 +21,7 @@
+  <?php if (array_filter($header)) : ?>

It would be probably better to run array_filter in the preprocess code

dmitriy.trt’s picture

Status: Needs work » Needs review
StatusFileSize
new815 bytes

Yes, you're right.

dawehner’s picture

Status: Needs review » Needs work
+++ b/theme/theme.incundefined
@@ -605,6 +605,11 @@ function template_preprocess_views_view_table(&$vars) {
+  // Hide table header if all labels are empty.
+  if (!array_filter($vars['header'])) {
+    $vars['header'] = array();

Even this might be hard to believe but i fear that people actually expect that a table with empty headers still appear. Maybe a settings should be used instead, but i'm not 100% sure about that.

jenlampton’s picture

Status: Needs work » Reviewed & tested by the community

If there are no labels, there certainly should be no header. That's why this is a bug report. :)

I've reviewed the patch and it works perfectly, thanks for the work on this!

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Some time ago i made some experience with people when some new css classes got added.

But sure i can refer to this issue if someone complains :p

mototribe’s picture

worked for me too! Thanks a bunch!
UWE

giorgio79’s picture

Thanks, I can confirm as well that Views 7 dev version works :)

dmitriy.trt’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.38 KB

Port to 6.x-3.x. Also prevents colspan="0" on empty text cell.

dmitriy.trt’s picture

StatusFileSize
new1.21 KB

Also, attaching patch for 7.x-3.x with the fix for appearing colspan="0".

13rac1’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
StatusFileSize
new1.11 KB

Fixes go to current dev (7.x in this case) before being applied to 6.x. This patch combines #18 and #25. Please test and rtbc.

Status: Needs review » Needs work

The last submitted patch, do_not_render_empty_header-1309026-26.patch, failed testing.

13rac1’s picture

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

Argh. I'm not working on my normal computer... try this one bot!

dmitriy.trt’s picture

StatusFileSize
new1.21 KB

#18 has been already committed, so just use #25 for 7.x-3.x to apply fix for colspan="0".

chris matthews’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 6 year old patch in #29 does not apply to the latest views 7.x-3.x-dev and if still applicable needs a reroll.

Checking patch theme/theme.inc...
error: while searching for:
  $vars['classes_array'] = array('views-table');
  if (empty($vars['rows']) && !empty($options['empty_table'])) {
    $vars['rows'][0][0] = $view->display_handler->render_area('empty');
    // Calculate the amounts of rows with output.
    $vars['field_attributes'][0][0]['colspan'] = count($vars['header']);
    $vars['field_classes'][0][0] = 'views-empty';
  }

error: patch failed: theme/theme.inc:637
error: theme/theme.inc: patch does not apply
andrew answer’s picture

Status: Needs work » Needs review
andrew answer’s picture

StatusFileSize
new824 bytes

Patch rerolled/fixed after last commits.