Hello,

in one of my views, I use the "grid"-style (3 columns - no grouping - horizontal). The view is used for an online gallery that has changing numbers of pictures.

I center images in each box of the grid with css.

Since the update to views 6.x-2.10 I have the following problem:
If the view has only one image, this image is displayed centered of the whole view width: === =X= ===

Before the update of views, it was correctly centered in the left "grid box" (grid with 3 columns): =X= === ===

Looking at the source code of the view output, I see the following:

<div class="view-content">
 <table class="views-view-grid">
  <tbody>
   <tr class="row-1 row-first row-last">
    <td class="col-1">
     ... content ...
    </td>
   </tr>
  </tbody>
 </table>
</div>

The problem seems to be that there are no <td></td> for the 2 empty columns of the row. I think there were some before the update?

Has something been changed with the grid style? Is there a new setting somewhere?
It would be very good if an existing row could be filled with empty <td></td> to style it easier...

Comments

dawehner’s picture

Status: Active » Fixed

The problem seems to be that there are no <td></td> for the 2 empty columns of the row. I think there were some before the update?

This was a feature request. To get back the old behavior, you need this preprocess code:

  $view     = $vars['view'];
  $result   = $view->result;
  $options  = $view->style_plugin->options;
  $handler  = $view->style_plugin;

  $columns  = $options['columns'];

  $rows = array();

  if ($options['alignment'] == 'horizontal') {
    $row = array();
    $row_count = 0;
    foreach ($vars['rows'] as $count => $item) {
      $row[] = $item;
      $row_count++;
      if (($count + 1) % $columns == 0) {
        $rows[] = $row;
        $row = array();
        $row_count = 0;
      }
    }
    if ($row) {
      // Fill up the last line.
      for ($i = 0; $i < ($columns - $row_count); $i++) {
        $row[] = '';
      }
      $rows[] = $row;
    }
  }
  else {
    $num_rows = floor(count($vars['rows']) / $columns);
    // The remainders are the 'odd' columns that are slightly longer.
    $remainders = count($vars['rows']) % $columns;
    $row = 0;
    $col = 0;
    foreach ($vars['rows'] as $count => $item) {
      $rows[$row][$col] = $item;
      $row++;

      if (!$remainders && $row == $num_rows) {
        $row = 0;
        $col++;
      }
      else if ($remainders && $row == $num_rows + 1) {
        $row = 0;
        $col++;
        $remainders--;
      }
    }
    for ($i = 0; $i < count($rows[0]); $i++) {
      // This should be string so that's okay :)
      if (!isset($rows[count($rows) - 1][$i])) {
        $rows[count($rows) - 1][$i] = '';
      }
    }
  }
  $vars['rows'] = $rows;
merlinofchaos’s picture

Hmm? I thought the feature request was to *ensure* that we had tds? Because without the tds the grids look odd. :/

Maybe we need to make it a switch.

dawehner’s picture

Status: Fixed » Active
[20:24] <dereine> merlinofchaos: to http://drupal.org/node/768162
[20:24] <dereine> there was a feature request to fill up the tds, thats working fine
[20:24] <dereine> but there was a feature request to not fill it, when there is just one row

Perhaps this should be configurable?

MJH’s picture

Thanks for your answers.

I already found the source of my problem:
http://drupal.org/node/451208
Patch in #24, committed to all branches

I revoked the patch and everything works normally again.

===

It seems that the new patch
- does include empty <td></td> if there is more than one row
- does NOT include empty <td></td> if there is only one row

Having empty <td></td> makes it a lot easier to theme the grid view. And the <td></td> should not cause any problems (nothing that could not be hidden with css).

So they should be there even if the grid view has only one row... (my opinion)

dawehner’s picture

It seems that the new patch
- does include empty <td></td> if there is more than one row
- does NOT include empty <td></td> if there is only one row

Having empty <td></td> makes it a lot easier to theme the grid view. And the <td></td> should not cause any problems (nothing that could not be hidden with css).

So they should be there even if the grid view has only one row... (my opinion)

So you want to make it configurable.

On earlier days views 2.0, for example, this feature didn't exist at all, the rows wasn't poluted

merlinofchaos’s picture

Hm. Ok, no, in that case the issue is that the behavior is inconsistent. Every row should always have a full column's worth of tds. Maybe that patch I committed was simply wrong.

dawehner’s picture

I think it was a valid feature request. I think there are two different kind of use cases.

merlinofchaos’s picture

Perhaps, but feature requests that change basic behavior must be weighed carefully, lest this happen. I didn't understand clearly enough what was wrong, I somehow though the patch had an error when there was only one row.

dawehner’s picture

We need better/more communication

jwaxman’s picture

What happened with this?
Is it going back to the old way (empty tds)?
If not, is there a way to get around this with CSS?

I, like a lot people, I guess, have a gallery of thumbnail photos laid out as a grid.
If there are fewer then a row's worth of thumbnails, they distribute themselves over the width of the table rather than lining up to the left the way I'd like.
Specifying fixed-layout and specifying percentage column widths in the td tags doesn't work to fix this.
Thanks

merlinofchaos’s picture

Title: Grid style: <td></td> for empty boxes of grid » Revert change to grid style that changed basic behavior
Category: support » task
Priority: Minor » Critical

This needs to go back to the old way. Sorry for letting it drop. I'll deal with it this week.

jwaxman’s picture

Many thanks.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new1.69 KB

Here is a patch which reverts the default behavior and make it configurable. So by default all columns gets displayed

dawehner’s picture

StatusFileSize
new1.69 KB

Update to minimal code style issue(whitespaces)

merlinofchaos’s picture

Status: Needs review » Fixed

Committed. I, er, accidentally committed #13 though. What was the actual diff between #13 and #14? My eyes aren't picking it out.

tim.plunkett’s picture

In #13, line 17 of the patch introduced trailing whitespace, so now line 44 of plugins/views_plugin_style_grid.inc has trailing whitespace.

Status: Fixed » Closed (fixed)

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