Skip to content

Commit

Permalink
Search ext: Ensure all non-grouped columns are aggregated if using GR…
Browse files Browse the repository at this point in the history
…OUP BY
  • Loading branch information
colemanw committed Sep 18, 2020
1 parent 7da9d07 commit 70e0043
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ext/search/ang/search/crmSearch.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
controller: function($scope, $element, $timeout, crmApi4, dialogService, searchMeta, formatForSelect2) {
var ts = $scope.ts = CRM.ts(),
ctrl = this;

this.DEFAULT_AGGREGATE_FN = 'GROUP_CONCAT';

this.selectedRows = [];
this.limit = CRM.cache.get('searchPageSize', 30);
this.page = 1;
Expand Down Expand Up @@ -133,6 +136,17 @@
$('.crm-search-results', $element).css('height', '');
}

// Ensure all non-grouped columns are aggregated if using GROUP BY
function aggregateGroupByColumns() {
if (ctrl.params.groupBy) {
_.each(ctrl.params.select, function(col, pos) {
if (!_.contains(col, '(') && ctrl.canAggregate(col)) {
ctrl.params.select[pos] = ctrl.DEFAULT_AGGREGATE_FN + '(' + col + ')';
}
});
}
}

// Debounced callback for loadResults
function _loadResultsCallback() {
// Multiply limit to read 2 pages at once & save ajax requests
Expand Down Expand Up @@ -181,6 +195,7 @@

function loadResults() {
$scope.loading = true;
aggregateGroupByColumns();
_loadResults();
}

Expand Down

0 comments on commit 70e0043

Please sign in to comment.