Is there a way to hide a row that is empty? When I tick the box "Hide Column if Empty" all the secondary rows disappear. I tried the field settings and chose "Hide if Empty" from the "No Results Bahaviour" area nothing happens.
Is there anyway I can hide empty columns while use this module?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MarMax’s picture

Component: Documentation » Code
Category: support » bug

I have the same issue. The second row is not rendered when "Hide if Empty" of any field in the first row is ticked. I don't think this is a documentation problem, is it?

arancedisicilia’s picture

I struggled a lot with weird behaviours, when I realized that hiding any of the fields was causing the secondary row not to be rendered.
Actually, I'm pretty sure this is a bug, but can't really nail it down.

Anyway, I think I narrowed it, since the problem seems to be in this piece of code:

if (!empty($options['info'][$field]['empty_column'])) {
      $empty = TRUE;
      foreach ($vars['rows'] as $num => $columns) {
        $empty &= empty($columns[$column]);
      }
      if ($empty) {
        foreach ($vars['rows'] as $num => &$column_items) {
          unset($column_items[$column]);
          unset($vars['header'][$column]);
      }
   }
}

and particularly in the "mysterious" line:

$empty &= empty($columns[$column]);

Commenting that line out does solve the problem for me.
Actually, I don't understand what that line's for, since both the header and column are removed a few lines later:

unset($column_items[$column]);
unset($vars['header'][$column]);

Not only the secondary row is rendered correctly, but the hidden fields are removed too from the view.
Maybe bojanz can help understand what's going on?

arancedisicilia’s picture

I'm sorry for a terrible mistake I made on post #2, since the line I had doubt is evidently to check if the contents of the whole column are empty. So that line can't be removed, otherwise the column will be always hidden.

I hope to come up with something new. Sorry again!

timtk’s picture

Not a problem thank for looking into arancedisicilia. Look forward to your solution

timtk’s picture

Issue summary: View changes

Spelling correction

johnv’s picture

Category: Bug report » Feature request
Issue summary: View changes
gruda’s picture

This patch will add the classes 'views-secondary-row--no-content' and 'hidden' to rows with empty fields. This will not work if twig debugging it turned on.

gruda’s picture

Status: Active » Needs review
gruda’s picture

FileSize
905 bytes

Fixed the paths.

gruda’s picture

This patch will add the classes 'views-secondary-row--no-content' and 'hidden' to rows with empty fields. This will not work if twig debugging is turned on. Re-rolled against the current branch.

johnv’s picture

Version: 7.x-3.6 » 8.x-1.x-dev
Status: Needs review » Fixed

Thanks, committed the patch to D8/D9-version.

johnv’s picture

Status: Fixed » Needs review

  • johnv committed c69095e on 8.x-1.x authored by gruda
    Issue #2066745 by gruda: How to hide a row with no content in it.
    
johnv’s picture

Status: Needs review » Fixed
johnv’s picture

Version: 8.x-1.x-dev » 8.x-1.0

Setting to the version in which is was found. it will be fixed in curent -dev version and next stable version.

  • johnv committed 2335fe9 on 8.x-1.x authored by gruda
    Issue #2066745 by gruda: How to hide a row with no content in it.
    
johnv’s picture

Title: How to hide a row with no content in it. » Hide rows without content

Status: Fixed » Closed (fixed)

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