1

In Drupal 7, I have Views table-output like this:

+--------+----------+--------+
| Tool   | Status   | Number |
+--------+----------+--------+
| Hammer | Broken   | 3      |
| Hammer | Borrowed | 10     |
+--------+----------+--------+ 

I want to change the output into:

+--------+--------+----------+
| Tool   | Broken | Borrowed |
+--------+--------+----------+
| Hammer | 3      | 10       |
+--------+--------+----------+

Is this possible? I prefer without custom coding.

1

Use views template, In advanced section, there is an option for theming - Theme:Information. Choose template from there or simply use views-view-table--yourviewname.tpl.php.

debug your rows here and add css classes to customize the output as per you want.

Take below code as a reference.

<?php
/**
 * @file
 * Template to display a view as a table.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $header: An array of header labels keyed by field id.
 * - $caption: The caption for this table. May be empty.
 * - $header_classes: An array of header classes keyed by field id.
 * - $fields: An array of CSS IDs to use for each field id.
 * - $classes: 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.
 * - $field_classes: An array of classes to apply to each field, indexed by
 *   field id, then row number. This matches the index in $rows.
 * @ingroup views_templates
 */
$i = 0;
$cnt = count($rows);
?>

<?php foreach ($rows as $row_count => $row): ?> 
    <div class="col-md-3 col-sm-3 col-xs-12">
        <div class="bod-item">
        <div class="member-wrapper" id="<?php print $row_count; ?>">
            <?php
            $url = $row['field_profile_image'];
            ?>

        </div>  
    </div>
    </div>
<?php endforeach; ?>
0

I think I managed to solve this, using these modules: views_php and views_aggregator.

With option use aggregation ON and using views_php, I create two Global PHP Fields which utilize $data variable.

Then, using views_aggregator table format, I apply Group Function to the Global PHP Fields above.

0

IMO there is no easy solution to create such kind of view using the Views module. The previous answers seem to somehow confirm this.

However the Forena module (disclosure: I'm a co-maintainer) can be used for this type of reporting. More specifically by using its facility to create a Display of a table in crosstab format.

A crosstab table is a table with a special layout. It is formatted as a grid, with:

  • the rows representing one or more (combinations of) facts, such as countries or regions, names of persons (or users) like employees / salespeople (or user IDs / user names), etc.
  • the columns representing one or more other facts, such as periods (months of a year, years, etc), available types/flavors of something (like types of errors), etc.
  • the intersections of rows and columns containing the actual information (data), such as summarized information (counts of something), timestamps, etc. and which might (optionally) include a hyperlink to a drill-down report.

Below is a sample of a crosstab report (including drilldown links also, i.e. the numbers in red in it):

enter image description here

Refer to my comment in the Forena issue queue for more details about the above screenshot. And/or have a look at the video about How to generate crosstab reports with graphs (Forena also supports charting of those data, a typical related requirement ...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.