3. Omitting Rows/Columns

Last updated on
30 April 2025

When a table is generated using the form_panel_table theme, missing rows and columns will be merged. This means that appropriate rowspan/colspan attributes are generated automatically.

But it's not always possible to describe a table accurately using this method, so some compromises have to be made.

By default, colspans are used to merge each filled cell with any empty cells to its right. If the row starts with empty cells, they are created first. If the #form_panel_table_span_rows attribute is TRUE, then this same procedure will be used to merge cells downward, instead. The exception is the header row, if present, which is always merged horizontally to the right.

For example, let's say we have some code like this:

  $form = array(
    '#theme' => 'form_panel_table',
    '#form_panel_table_attributes' => array('border' => 1),
    '#form_panel_weights_decimal' => TRUE);
  $i = ord('A');
  $form[chr($i)] = array('#value' => chr($i++), '#weight' => 2.1);
  $form[chr($i)] = array('#value' => chr($i++), '#weight' => 2.2);
  $form[chr($i)] = array('#value' => chr($i++), '#weight' => 3.1);
  print drupal_render($form);

In this case, we've omitted (row=3, col=2), so the generated table looks something like this:

  +---+---+
  | A | B |
  +---+---+
  | C     |
  +-------+

If, instead, we set #form_panel_table_span_rows to TRUE, we get:

  +---+---+
  | A | B |
  +---+   |
  | C |   |
  +---+---+

If we then change the code to make the first row the header (by reducing its number to 1), we get:

  $form = array(
    '#theme' => 'form_panel_table',
    '#form_panel_table_attributes' => array('border' => 1),
    '#form_panel_table_span_rows' => TRUE,
    '#form_panel_weights_decimal' => TRUE);
  $i = ord('A');
  $form[chr($i)] = array('#value' => chr($i++), '#weight' => 1.1);
  $form[chr($i)] = array('#value' => chr($i++), '#weight' => 1.2);
  $form[chr($i)] = array('#value' => chr($i++), '#weight' => 3.1);
  +---+---+
  | A | B |
  +===+===+
  | C |   |
  +---+---+

To see what happens when missing cells are in the leftmost or top position, consider this example:

  $form = array(
    '#theme' => 'form_panel_table',
    '#form_panel_table_attributes' => array('border' => 1),
    '#form_panel_weights_decimal' => TRUE);
  $i = ord('A');
  $form[chr($i)] = array('#value' => chr($i++), '#weight' => 2.2);
  $form[chr($i)] = array('#value' => chr($i++), '#weight' => 3.1);
  $form[chr($i)] = array('#value' => chr($i++), '#weight' => 3.2);
  +---+---+
  |   | A |
  +---+---+
  | B | C |
  +---+---+

In this case, the upper-left cell contains the HTML entity  , by default. This can be changed using the #form_panel_table_filler attribute.

You can, of course, have multiple omitted cells in your table. Depending on the situation, the browser may choose to ignore some of the spans, however. So the table may not always look the way you intended.

Help improve this page

Page status: Not set

You can: