I apologize in advance if this is already possible. The fantastic Views module has so many features, I may be getting confused :).

First, I would like to filter a tabular list according to a given taxonomy term. This is easy to do in the filter settings. So far so good. But then I would like to use the terms of another taxonomy vocabulary as a column in the table -- so that the user can see more features of each node and sort the table according to this vocabulary.

For example, I filter the table to contain only nodes of the "Fruit" category. But then I would like to list the kind of fruit, e.g., apple, pear, orange, next to the name of the node.

Thanks for a truly great module!

--Neil

Comments

merlinofchaos’s picture

I have good news and I have bad news.

The good news is that yes you can do this.

The bad news is that the only reasonable way to do it is with a theme. Because there's a variable number of terms, it's pretty difficult to get anything other than the term that you're sorting/filtering on.

If you theme it, however, you can do load the node, or just load the terms. It's less efficient but I think the only way to do what you want.

The good news is that theming isn't hard. ASsuming phptemplate:

phptemplate_views_view_viewname($view, $type, $level, $items) {

}

Copy the code from theme_views_view() in views.module and replace the switch with the contents of views_view_table(). Then you can just add columns as you need.

merlinofchaos’s picture

Now that I'm a bit more awake I went ahead and put the function a bit more together for you.

Replace VIEWNAME with the view you want, and you can add fields to your heart's content by
adding another $cell structure to the row.

function phptemplate_views_view_VIEWNAME($view, $type, $nodes) {
  if ($view->header)
    $output = "<div class='view-header' id='view-header-$view->name'>$view->header</div>\n";

  $fields = _views_get_fields(); 

  foreach ($nodes as $node) {
    $row = array();
    // Right in here is where you'll add your own fields.
    // The fields are order dependent, but what you can do is
    // $rows[COLUMNNUMBER] = $your_cell_here;
    // then add sort($row) right before $rows[] = $row
    foreach ($view->field as $field) {
      $cell['data'] = _views_handle_field($fields, $field, $node);
      $cell['class'] = 'view-field';
      $cell['id'] = "view-field-$field[queryname]";
      $row[] = $cell;
    }
    $rows[] = $row;
  }
  $output = theme('table', $view->table_header, $rows);

  return "<div class='view' id='view-$view->name'>$output</div>\n";
}
merlinofchaos’s picture

Leaving this as active because this is a nice start for an example in the theming documentation which still needs to be written.

ohzbees’s picture

Awesome! I don't have time right now to try it out, but I will soon.

merlinofchaos’s picture

Title: List Taxonomy Terms In a Table » Views Example for Documentation
Assigned: Unassigned » merlinofchaos
Category: feature » task
Priority: Normal » Minor

Changing title and parameters so that I remember what this is the when I look at my issues queue.

merlinofchaos’s picture

Status: Active » Closed (duplicate)

Using http://drupal.org/node/47845 to track the documentation now. Including a back-reference.