diff --git a/core/ViewDataTable/Config.php b/core/ViewDataTable/Config.php index 0389c213fb239f49525c007b24be00a8a1c3b840..a2be3f6c966199905da1f5049382f188cdaba720 100644 --- a/core/ViewDataTable/Config.php +++ b/core/ViewDataTable/Config.php @@ -86,7 +86,8 @@ class Config */ public $clientSideProperties = array( 'show_limit_control', - 'pivot_by_dimension' + 'pivot_by_dimension', + 'pivot_by_column' ); /** @@ -200,6 +201,11 @@ class Config */ public $pivot_by_dimension; + /** + * The column to display in pivot tables. Defaults to the first non-label column if not specified. + */ + public $pivot_by_column = false; + /** * Controls whether the footer icon that allows users to switch to the 'normal' DataTable view * is shown. diff --git a/plugins/CoreHome/javascripts/dataTable.js b/plugins/CoreHome/javascripts/dataTable.js index 5bcb96d5a6ef75b8f4421fac2d72162a6dc1502c..1c44546803d469c682a5c66e906629619f580568 100644 --- a/plugins/CoreHome/javascripts/dataTable.js +++ b/plugins/CoreHome/javascripts/dataTable.js @@ -156,7 +156,8 @@ $.extend(DataTable.prototype, UIControl.prototype, { 'flat', 'include_aggregate_rows', 'totalRows', - 'pivotBy' + 'pivotBy', + 'pivotByColumn' ]; for (var key = 0; key < filters.length; key++) { @@ -1092,6 +1093,9 @@ $.extend(DataTable.prototype, UIControl.prototype, { } if (self.param.pivotBy) { str += '&pivotBy=' + self.param.pivotBy; + if (self.props.pivot_by_column) { + str += '&pivotByColumn=' + self.props.pivot_by_column; + } } if (format == 'CSV' || format == 'TSV' || format == 'RSS') { str += '&translateColumnNames=1&language=' + piwik.language; @@ -1267,8 +1271,12 @@ $.extend(DataTable.prototype, UIControl.prototype, { .click(generateClickCallback('pivotBy', null, function () { if (self.param.pivotBy) { self.param.pivotBy = ''; + self.param.pivotByColumn = ''; } else { self.param.pivotBy = self.props.pivot_by_dimension; + if (self.props.pivot_by_column) { + self.param.pivotByColumn = self.props.pivot_by_column; + } } })); @@ -1644,6 +1652,7 @@ $.extend(DataTable.prototype, UIControl.prototype, { } delete self.param.pivotBy; + delete self.param.pivotByColumn; // do ajax request self.reloadAjaxDataTable(true, function (newReport) { diff --git a/plugins/Events/Events.php b/plugins/Events/Events.php index ad4dab646f70f8fbed1b4dadce3f898f82897075..3d335bd229f9ee955a0aa84bf98b2b5dd062e6df 100644 --- a/plugins/Events/Events.php +++ b/plugins/Events/Events.php @@ -162,7 +162,11 @@ class Events extends \Piwik\Plugin $secondaryDimension = $this->getSecondaryDimensionFromRequest(); $view->config->subtable_controller_action = API::getInstance()->getActionToLoadSubtables($apiMethod, $secondaryDimension); - $view->config->columns_to_display = array('label', 'nb_events', 'sum_event_value'); + + if (Common::getRequestVar('pivotBy', false) === false) { + $view->config->columns_to_display = array('label', 'nb_events', 'sum_event_value'); + } + $view->config->show_flatten_table = true; $view->config->show_table_all_columns = false; $view->requestConfig->filter_sort_column = 'nb_events'; @@ -175,6 +179,7 @@ class Events extends \Piwik\Plugin $subtableReport = Report::factory('Events', $view->config->subtable_controller_action); $view->config->pivot_by_dimension = $subtableReport->getDimension()->getId(); + $view->config->pivot_by_column = 'nb_events'; } private function addRelatedReports($view, $secondaryDimension)