By Anonymous (not verified) on
I'm building a site with Drupal 7 and want to emulate the flipped table view as provided by Views Hacks. I tried to reuse the code as showed in http://drupal.org/node/174578 but this doesn't run " as is" on Drupal 7.
I modified line 11 to show "print $classes" instead of "print $class" but still get errors on other lines
(eg: on line 21:
foreach($row['title'] as $title):
error message is :
undefined index: title in include()
Is there anyone who knows how to make this code work in Drupal 7?
Full Drupal6 working code from previous post:( http://drupal.org/node/174578 )
<?php
$row = array();
foreach ($rows as $col){
foreach ($col as $ltr => $value){
$row[$ltr][] = $value;
}
}
$first = TRUE;
$element = 'odd';
?>
<table class="<?php print $class; ?>">
<?php if (!empty($title)) : ?>
<caption><?php print $title; ?></caption>
<?php endif; ?>
<?php if ($first):?>
<thead>
<tr class="<? 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';
if (!$first): ?>
<tbody>
<?php foreach ($row as $cck_field => $rowname):?>
<?php if ($cck_field != title): ?>
<tr class="<? echo $element; ?>">
<th>
<?php echo $header[$cck_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';
}
endif; //cck_field != title
endforeach; ?>
</tbody>
<?php endif; //!first ?>
</table>
.
Comments
Flipped table working in Drupal 7
I finally got the flipped table code working in my drupal 7.
In the views selected fields I added the node title field and then modified line 11 and 21 of the code as in the code listing below.
I hope this might work for other people as well.
Stan
I'm in the same boat...
I'm in the same boat... trying to figure this out.
It's strange... if I remove the Node Title from "Fields" then look at my views page... I get an error like you:
Notice: Undefined index: title in include() (line 21 of /home/www/domain.com/htdocs/sites/all/modules/views/theme/views-view-table.tpl.php).
Warning: Invalid argument supplied for foreach() in include() (line 21 of /home/www/domain.com/htdocs/sites/all/modules/views/theme/views-view-table.tpl.php).
BUT my view displays properly... I see two items on one line...
If I add the title back to fields... I don't get an error but it displays one item per line.
I'm using your code from the 2nd post. I put it in file "views-view-table.tpl.php" which is located in sites/all/modules/views/theme for me. Is there something I'm not getting?
A couple of small changes
I made a few small changes, some of the <? code needed <?php in order for the zebra striping to work.
In my case, I didn't use a title, and didn't need a thead section as I am not making my fields sortable. I don't think that I needed any information that may have been contained there.
With this code, I don't get any errors and my display is working great. It may not work for everyone, in every situation, but it definitely works.
I changed the template file to views-view-table-tableviewname.tpl.php in order to select just one section instead of changing the table display for the entire site.
I also added a first and last class to the table for themeing.
Attributes in TD tag?
I have flipped tables working using this code, but I used Style settings/Customize field HTML in Views to print out a new CSS class in the TDs. Does anyone know how I could get the TD attributes, so the class name will print? Thanks.
Subscribe customised classe
Subscribe!
I'm also looking for a way to use customised classes for full theming flexibility.
Did you find a proper way ?