Hi,

I am trying to use a view with a flipped table within quicktabs and would like the tab to not display at all, when the views is empty. This is working fine when I set the view to display as a regular table.

When I set the view to a flipped table though, the tab still shows even though the fields are not holding any data. I have set everything to not display when empty and even installed filters for every field in the view ("not empty") but with no luck. So I assume the view still does display some kind of markup or similar which leads e.g. quicktabs to the assumption that the view is not empty.

I might be completely wrong though - that's just an idea from a beginner.

But in case this is true: Can this behaviour be avoided somehow?

Thanks in advance for any help.

CommentFileSizeAuthor
#5 1587862-empty-view-not-empty-5.patch798 bytesnaught101

Comments

joachim’s picture

Status: Active » Postponed (maintainer needs more info)

Have you checked the actual markup that comes out of the tab? Check the flipped table TPL file for any obvious problems.

Can you also check the markup that the same view result provides as, say, a page, both as a regular and flipped table?

pbrough’s picture

The TPL file will always provide a result, even if it is an empty table.

I have added some extra checks to the template to test if the rows contain any information before the table mark up.

I have included the complete template file here.

<?php
/**
 * @file views-flipped-table.tpl.php
 * Template to display a view as a table with rows and columns flipped.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $header: An array of header labels keyed by field id.
 * - $fields: An array of CSS IDs to use for each field id.
 * - $class: A class or classes to apply to the table, based on settings.
 * - $row_classes: An array of classes to apply to each row, indexed by row
 *   number. This matches the index in $rows.
 * - $rows: An array of row items. Each row is an array of content.
 *   $rows are keyed by row number, fields within rows are keyed by field ID.
 *   
 * @ingroup views_templates
 */
?>
<?php
  // Flip the table.
  $row = array();
  foreach ($rows as $col){
    foreach ($col as $ltr => $value){
      $row[$ltr][] = $value;
    }
  }
  $first = isset($row['title']);
  $element = 'odd';
?>
<?php if (!empty($row)) : // Test to see if rows contain any data ?> 
<table class="<?php print $class; ?>">
  <?php if (!empty($title)) : ?>
    <caption><?php print $title; ?></caption>
  <?php endif; ?>

  <?php if ($first) : ?>
  <thead>
    <tr class="<?php echo $element; ?>">
      <th>
      </th>
      <?php foreach ($row['title'] as $title) : ?>
      <th>
      <?php echo $title; ?>
      </th>
      <?php endforeach; ?>
    </tr>
  </thead>
  <?php  
    $first = FALSE;
    endif; //$first
    $element = 'even';
  ?>  
 <tbody>
    <?php foreach ($row as $field => $rowname) : ?>
      <?php if ($field != 'title') : ?>
      <tr class="<? echo $element; ?>">
        <th>
          <?php echo $header[$field]; ?>
        </th>
      <?php foreach ($rowname as $count => $item): ?>
        <td>
          <?php echo $item; ?>
        </td>
      <?php endforeach; ?>
      </tr>
      <?php
        if ($element == 'odd'){
          $element = 'even';
        } else {
          $element = 'odd';
        }
      ?>
      <?php endif; // field != title ?>
    <?php endforeach; ?>
  </tbody>
</table>
<?php endif;  // field != row ?>

Hope this helps
Phil

----------------------------------------------------
Phillip Brough
Percontor Experiential Design

joachim’s picture

Status: Postponed (maintainer needs more info) » Needs work

Thanks for investigating.

Any chance you could post your change as a patch?

naught101’s picture

Project: Views Hacks » Views Flipped Table
Component: Views Flipped Table » Code
naught101’s picture

Status: Needs work » Closed (cannot reproduce)
StatusFileSize
new798 bytes

The change is apparently against 6.x-1.0-beta2, and the patch against 6.x-1.x is attached.

I'm not seeing this behaviour in 7.x at all though. Going to close.