Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I was trying to make a report via views in Drupal 7. It's quite easy to generate a table with the headers being the labels of the fields, like the following (being very straightforward):

:---------:----------:----------:----------:
| Label A | Label B  | Label C  | Label D  |
:---------:----------:----------:----------:
| Value A | Value B  | Value C  | Value D  |
:---------:----------:----------:----------:
|Value A' |Value B'  |Value C'  |Value D'  |
:---------:----------:----------:----------:

However, I am getting stumped at creating the following complex table:

:---------:----------:----------:----------:
|     Header A       |      Header B       |
:---------:----------:----------:----------:
| Label A | Label B  | Label C  | Label D  |
:---------:----------:----------:----------:
| Value A | Value B  | Value C  | Value D  |
:---------:----------:----------:----------:
|Value A' |Value B'  |Value C'  |Value D'  |
:---------:----------:----------:----------:

Any ideas on how to approach this? Thanks :)

share|improve this question
you can add a header and then style it in css to look like as if it part of the table – Aboodred1 May 6 at 15:36

2 Answers

The Views UI supports this.

Once you have your View configured, click on the "Settings" link in the Format section. You will then see a table that allow you to choose which column each field should appear in. See screenshot below. In this example, if you wanted the Author uid and Nid fields to appear in the same column, you would just select Author uid from the select list next to Nid (or vice versa).

enter image description here

share|improve this answer

You can also try theme_table and colspan attribute

$header = array( array('data' => 'Header A', 'colspan' => 2), array('data' => 'Header B', 'colspan' => 2));
$rows[] = array('Label A', 'Label B', 'Label C', 'Label D');
$rows[] = array('value A', 'value B', 'value C', 'value D');
$rows[] = array('value A', 'value B', 'value C', 'value D');
$rows[] = array('value A', 'value B', 'value C', 'value D');
$output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' =>  $attributes));

print $output;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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