You are here

public function reference_table_formatter_base_type::hide_empty_columns in Reference Table Formatter 7

Hide columns in a table which are empty.

Parameters

$table: A renderable table array.

1 call to reference_table_formatter_base_type::hide_empty_columns()
reference_table_formatter_base_type::render_table in ./reference_table_formatter_base_type.inc
Render a table of content from the plugin.

File

./reference_table_formatter_base_type.inc, line 276
A base class for the "reference type" plugin.

Class

reference_table_formatter_base_type
Class reference_table_formatter_base_type

Code

public function hide_empty_columns(&$table) {
  $rows =& $table['#rows'];
  $display_columns = array_fill(0, count($rows[0]), FALSE);
  foreach ($rows as $row) {
    foreach ($row as $column_index => $column) {
      if (!empty($column)) {
        $display_columns[$column_index] = TRUE;
      }
    }
  }
  foreach ($display_columns as $index => $display_column) {
    if ($display_column === FALSE) {
      unset($table['#header'][$index]);
      foreach ($rows as &$row) {
        unset($row[$index]);
      }
    }
  }
}