diff --git a/src/plugins/table_vis/public/table_vis.html b/src/plugins/table_vis/public/table_vis.html
index 33fdf9cf5e8f1..8e9b1f1f9660d 100644
--- a/src/plugins/table_vis/public/table_vis.html
+++ b/src/plugins/table_vis/public/table_vis.html
@@ -9,7 +9,9 @@
No results found
group="tableGroups"
export-title="vis.title"
per-page="vis.params.perPage"
- sort="sort">
+ sort="sort"
+ show-total="vis.params.showTotal"
+ total-func="vis.params.totalFunc">
diff --git a/src/plugins/table_vis/public/table_vis.js b/src/plugins/table_vis/public/table_vis.js
index 91a6d00da2668..85ede8dbd9bb5 100644
--- a/src/plugins/table_vis/public/table_vis.js
+++ b/src/plugins/table_vis/public/table_vis.js
@@ -42,7 +42,9 @@ function TableVisTypeProvider(Private) {
sort: {
columnIndex: null,
direction: null
- }
+ },
+ showTotal: false,
+ totalFunc: 'sum'
},
editor: ''
},
diff --git a/src/plugins/table_vis/public/table_vis_params.html b/src/plugins/table_vis/public/table_vis_params.html
index 9c846808e065a..16c24dc67cf62 100644
--- a/src/plugins/table_vis/public/table_vis_params.html
+++ b/src/plugins/table_vis/public/table_vis_params.html
@@ -23,3 +23,19 @@
Calculate metrics for every bucket/level
+
+
+
+
+
+
+
+
+
diff --git a/src/plugins/table_vis/public/table_vis_params.js b/src/plugins/table_vis/public/table_vis_params.js
index 3b1e703ede435..5bd00795dae6d 100644
--- a/src/plugins/table_vis/public/table_vis_params.js
+++ b/src/plugins/table_vis/public/table_vis_params.js
@@ -8,6 +8,8 @@ uiModules.get('kibana/table_vis')
restrict: 'E',
template: tableVisParamsTemplate,
link: function ($scope) {
+ $scope.totalAggregations = ['sum', 'avg', 'min', 'max', 'count'];
+
$scope.$watchMulti([
'vis.params.showPartialRows',
'vis.params.showMeticsAtAllLevels'
diff --git a/src/ui/public/agg_table/agg_table.html b/src/ui/public/agg_table/agg_table.html
index 6e1a940fc0c4f..266d975589384 100644
--- a/src/ui/public/agg_table/agg_table.html
+++ b/src/ui/public/agg_table/agg_table.html
@@ -3,7 +3,9 @@
rows="rows"
columns="formattedColumns"
per-page="perPage"
- sort="sort">
+ sort="sort"
+ show-total="showTotal"
+ totalFunc="totalFunc">
Export:
diff --git a/src/ui/public/agg_table/agg_table.js b/src/ui/public/agg_table/agg_table.js
index 1165de1244be9..a6853254ef8ec 100644
--- a/src/ui/public/agg_table/agg_table.js
+++ b/src/ui/public/agg_table/agg_table.js
@@ -16,7 +16,9 @@ uiModules
table: '=',
perPage: '=?',
sort: '=?',
- exportTitle: '=?'
+ exportTitle: '=?',
+ showTotal: '=',
+ totalFunc: '='
},
controllerAs: 'aggTable',
compile: function ($el) {
@@ -93,6 +95,35 @@ uiModules
formattedColumn.class = 'visualize-table-right';
}
+ const isFieldNumeric = (field && field.type === 'number');
+ const isFirstValueNumeric = _.isNumber(_.get(table, `rows[0][${i}].value`));
+
+ if (isFieldNumeric || isFirstValueNumeric) {
+ function sum(tableRows) {
+ return _.reduce(tableRows, function (prev, curr, n, all) {return prev + curr[i].value; }, 0);
+ }
+
+ switch ($scope.totalFunc) {
+ case 'sum':
+ formattedColumn.total = sum(table.rows);
+ break;
+ case 'avg':
+ formattedColumn.total = sum(table.rows) / table.rows.length;
+ break;
+ case 'min':
+ formattedColumn.total = _.chain(table.rows).map(i).map('value').min().value();
+ break;
+ case 'max':
+ formattedColumn.total = _.chain(table.rows).map(i).map('value').max().value();
+ break;
+ case 'count':
+ formattedColumn.total = table.rows.length;
+ break;
+ default:
+ break;
+ }
+ }
+
return formattedColumn;
});
});
diff --git a/src/ui/public/agg_table/agg_table_group.html b/src/ui/public/agg_table/agg_table_group.html
index 5a8defc96d26b..2c176524cd6a5 100644
--- a/src/ui/public/agg_table/agg_table_group.html
+++ b/src/ui/public/agg_table/agg_table_group.html
@@ -9,13 +9,21 @@
-
+
+ sort="sort"
+ show-total="showTotal"
+ total-func="totalFunc">
|
@@ -33,13 +41,21 @@
-
+
+ sort="sort"
+ show-total="showTotal"
+ total-func="totalFunc">
|
diff --git a/src/ui/public/agg_table/agg_table_group.js b/src/ui/public/agg_table/agg_table_group.js
index cfbf903299c9b..2cd1031182ba4 100644
--- a/src/ui/public/agg_table/agg_table_group.js
+++ b/src/ui/public/agg_table/agg_table_group.js
@@ -13,7 +13,9 @@ uiModules
group: '=',
perPage: '=?',
sort: '=?',
- exportTitle: '=?'
+ exportTitle: '=?',
+ showTotal: '=',
+ totalFunc: '='
},
compile: function ($el) {
// Use the compile function from the RecursionHelper,
diff --git a/src/ui/public/paginated_table/paginated_table.html b/src/ui/public/paginated_table/paginated_table.html
index d40155c0d1578..1d64e70180ce6 100644
--- a/src/ui/public/paginated_table/paginated_table.html
+++ b/src/ui/public/paginated_table/paginated_table.html
@@ -27,6 +27,11 @@
+
+
+ {{col.total | number}} |
+
+
diff --git a/src/ui/public/paginated_table/paginated_table.js b/src/ui/public/paginated_table/paginated_table.js
index 5f00db096f1c5..1fbef21b8479b 100644
--- a/src/ui/public/paginated_table/paginated_table.js
+++ b/src/ui/public/paginated_table/paginated_table.js
@@ -17,7 +17,9 @@ uiModules
perPage: '=?',
sortHandler: '=?',
sort: '=?',
- showSelector: '=?'
+ showSelector: '=?',
+ showTotal: '=',
+ totalFunc: '='
},
controllerAs: 'paginatedTable',
controller: function ($scope) {