Currently, if you do grouping in table-style, the output is one table per group, with the grouping field in the caption of each table.

The problem with this is, that col-width's are different per group(table).
In many cases, the output would be better looking, if all groups were in one table, with multiple tbody's.

I don't see cases where the multiple tables are a feature, so i set the issue as bug report.
But maybe there's a deeper reason for the current behaviour?

Comments

merlinofchaos’s picture

Category: bug » support
Status: Active » Closed (won't fix)

There's no real way to do this in the current architecture. The answer is to fix your column widths so they match. This is not a bug.

sirtet’s picture

Thanks.
I did not want to set the widths, so they could be set automatically depending on content.
And also from the reader's logic i think in many (most?) cases, all results in one table make more sense, because it's all the same data.

By saying "...no real way to...", do you mean that you can't access the data for thead outside the loop that outputs the groups?
Or is there another big downside to my approach?

So i did a (dirty?) solution which did not require much understanding of all the code behind,
by altering the tpl-files like this:

copied the views-view.tpl.php to views-view--[view-name]--page.tpl.php
and added the table-tag around the $rows:

  <?php if ($rows): ?>
    <div class="view-content">
    <table <?php if ($classes) { print 'class="'. $classes . '" '; } ?><?php print $attributes; ?>>
      <?php print $rows; ?>
      </table>
    </div>

then copied views-view-table.tpl.php to views-view-table--[view-name].tpl.php
removed the table- and thead-tags, plus outputted the title in a new row spanning all cols, with a class so i can style it separately.

  <tbody>
   <?php if (!empty($title)) : ?>
    <tr><th class="views-grouping-title" colspan="<?php echo count($header);?>"><?php print $title; ?></th></tr>
  <?php endif; ?>
    <tr>
      <?php foreach ($header as $field => $label): ?>
        <th <?php if ($header_classes[$field]) { print 'class="'. $header_classes[$field] . '" '; } ?>>
          <?php print $label; ?>
        </th>
      <?php endforeach; ?>
    </tr>

    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
        <?php foreach ($row as $field => $content): ?>
          <td <?php if ($field_classes[$field][$count]) { print 'class="'. $field_classes[$field][$count] . '" '; } ?><?php print drupal_attributes($field_attributes[$field][$count]); ?>>
            <?php print $content; ?>
          </td>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>

From looking at the code, i could not see if (and how) it would be possible to do a new view-style plugin with the approach i did, but i guess it should be not too hard...

mrfelton’s picture

Status: Closed (won't fix) » Active

I think we need an option to be able to specify wether the headers should repeat or not. In many cases it makes no sense to repeat the headers, and it can be really bad from an accessibility point of view where you have what is essentially one set of tabular data now being displayed in three distinct tables. Because the data is grouped by a certain field, doesn't (shouldn't) really mean it that it should be displayed as three completely different sets of data.

The issue of table widths can clearly be fixed by css but I think that's only a small part of this problem, hence I'm reopening this closed ticket.

mrfelton’s picture

My quick workaround was to preprocess the view to get some additional classes in there so that we could hide the repeating headers.

/**
 * Ad some additional classes into the cart table, to help us with the styling.
 */
function optics_theme_budget_preprocess_views_view_table(&$vars) {
  if ($vars['view']->name == 'commerce_cart_form') {
    static $optics_commerce_cart_table_count;
    $optics_commerce_cart_table_count = $optics_commerce_cart_table_count? $optics_commerce_cart_table_count : 1;
    $vars['classes_array'][] = 'table-group-' . $optics_commerce_cart_table_count;
    $optics_commerce_cart_table_count++;
  }
}
.view-commerce-cart-form table thead {
  display: none;
}

.view-commerce-cart-form table.table-group-1 thead {
  display: table-header-group;
}

Whilst it works visually, it still has accessibility issues because we have three tables for one set of tabular data.

merlinofchaos’s picture

Status: Active » Fixed

At this time that's not a workaround, that's the correct way to do it.

Not *everything* that's possible to do with Views can (or should) be doable in the UI.

Status: Fixed » Closed (fixed)

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

iantresman’s picture

Issue summary: View changes

Using D6, I found that if I grouped by the title, the title was showing for each row (in Tables, HTML Lists, etc).

To work around this, I created a new field which merely duplicated the title, and now I get a single table with the grouping field showing just once.

Another workaround, is to not display the Title as a link to the node, which in retrospect, makes sense.

shomoos’s picture

To work around this, I created a new field which merely duplicated the title, and now I get a single table with the grouping field showing just once.

can you clarify this please?

iantresman’s picture

@shomoos’s

I created a new text field, and just used this as the "title". The module Automatic Nodetitles lets you hide and ignore the node's actual title field.

I guess that if you must use the actual node title, you can still create another field that just copies the actual node title, using rules, or Computed Field. Apparently you can also do this with Views Bulk Operations.