diff --git a/includes/admin.inc b/includes/admin.inc index bc94ff5..8758e3e 100644 --- a/includes/admin.inc +++ b/includes/admin.inc @@ -3206,6 +3206,10 @@ function theme_views_ui_style_plugin_table($form) { 'data' => t('Default sort'), 'align' => 'center', ), + array( + 'data' => t('Hide empty column'), + 'align' => 'center', + ), ); $rows = array(); foreach (element_children($form['columns']) as $id) { @@ -3227,11 +3231,15 @@ function theme_views_ui_style_plugin_table($form) { $row[] = ''; $row[] = ''; } + $row[] = array( + 'data' => drupal_render($form['info'][$id]['empty_column']), + 'align' => 'center', + ); $rows[] = $row; } // Add the special 'None' row. - $rows[] = array(t('None'), '', '', '', array('align' => 'center', 'data' => drupal_render($form['default'][-1]))); + $rows[] = array(t('None'), '', '', '', array('align' => 'center', 'data' => drupal_render($form['default'][-1])), ''); $output .= theme('table', $header, $rows); $output .= drupal_render($form); diff --git a/plugins/views_plugin_style_table.inc b/plugins/views_plugin_style_table.inc index 0454fd1..745c0a7 100644 --- a/plugins/views_plugin_style_table.inc +++ b/plugins/views_plugin_style_table.inc @@ -229,6 +229,11 @@ class views_plugin_style_table extends views_plugin_style { '#process' => array('views_process_dependency'), '#dependency' => array($id => array($field)), ); + $form['info'][$field]['empty_column'] = array( + '#type' => 'checkbox', + '#default_value' => isset($this->options['info'][$field]['empty_column']) ? $this->options['info'][$field]['empty_column'] : FALSE, + '#dependency' => array($id => array($field)), + ); // markup for the field name $form['info'][$field]['name'] = array( diff --git a/theme/theme.inc b/theme/theme.inc index 0ce0a20..d2e4fc7 100644 --- a/theme/theme.inc +++ b/theme/theme.inc @@ -396,6 +396,20 @@ function template_preprocess_views_view_table(&$vars) { $vars['rows'][$num][$column] .= $field_output; } } + + // Remove columns if the option is hide empty column is checked and the field is not empty. + if (!empty($options['info'][$field]['empty_column'])) { + $empty = TRUE; + foreach ($vars['rows'] as $num => $columns) { + $empty &= empty($columns[$column]); + } + if ($empty) { + foreach ($vars['rows'] as $num => &$columns) { + unset($columns[$column]); + unset($vars['header'][$column]); + } + } + } } $count = 0;