ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

grouping/aggregation filter applying to entire aggregation string

Open meyerds opened this issue 11 years ago • 5 comments

This issue seen in the latest unstable build.

The aggregated values in a grouping header row have any cell filters applied after the aggregation string is built (e.g. filter runs against "avg: data" instead of against data), which causes many filters to fail.

See this issue in http://plnkr.co/edit/VBIbnVYcY4ra825647Vy

meyerds avatar Apr 17 '15 22:04 meyerds

That's what the option groupingSuppressAggregationText is for, it's documented on http://ui-grid.info/docs/#/tutorial/209_grouping

PaulL1 avatar Apr 17 '15 22:04 PaulL1

So it is... I scanned right over that part of the documentation.

I looked to see if it was an enhancement/fix I could contribute without much risk to the rest of ui-grid, but looking through the code it looks like it would require a number of changes all over in core pieces since grouping rows use the same row and cell templates as data rows.

As a temporary workaround for my own purposes I added the following to my cell template: {{row.groupHeader && col.grouping.aggregation ? (col.grouping.aggregation + ': ') : ''}} Not ideal, from a performance perspective, since the same cell template is used for every data row. But it's functional to get the aggregation text + filtered data.

meyerds avatar Apr 20 '15 19:04 meyerds

Based on your addition to the Future milestone, I guess you're in favor of leaving this open as a possible future enhancement/bugfix? Since it's documented that seems very reasonable. Thanks for the quick response.

meyerds avatar Apr 20 '15 19:04 meyerds

Yeah, although I have no idea how to actually change it, since the filters get applied via an angular binding. I could maybe write a filter that applies the totals/aggregations, and add that filter to the end of the filters, but it's getting a little too tricky I think.

In my code, I just unstring it in the filter. Most commonly I'm doing this on a reference data lookup (changing 1 => active, 2=> inactive or similar). I have a generic routine that makes filters for my ref data:

.factory('SystemRefDataService', function( ){
  var systemRefDataService = {
    genericMap: function( constant, constantName ) {
      return function (input) {
        var result;
        var match;

        if(!input) {
          return '';
        } else if (result = constant[input]) {
          return result;
        } else if ( ( match = input.match(/(\d+)( \(\d+\))/) ) && ( result = constant[match[1]] ) ) {
          return result + match[2];
        } else {
          if(!$rootScope[constantName + 'Error']) {
            LoggingService.logError('42001: ' + constantName + ' not recognised', 'SYSTEM_REF_DATA', {input: input});
            $rootScope[constantName + 'Error'] = true;
          }
          return 'MSG_base_42001_system_ref_data_not_recognised';
        }
      };
    }
  };

  return systemRefDataService; 
})

I hold most of my refData in constants in the format:

.factory( 'ProjectStatusesConstant', function() {
  return {
      1: 'VALUE_project_project_status_active',
      2: 'VALUE_project_project_status_inactive'
  };
})

So I can define a filter by:

.filter('mapProjectStatus', function( ProjectStatusesConstant, SystemRefDataService ) {
  return SystemRefDataService.genericMap( ProjectStatusesConstant, 'project_statuses');
})

PaulL1 avatar Apr 20 '15 21:04 PaulL1

I think this may be addressed in the newest version of grouping (which has significant breaking changes).

You can now define a customTreeAggregationFinalizerFn that doesn't concatenate the data, and then concatenate the data in a cellTemplate instead (the label and the value are both now separately available for you to do things with if you wish).

PaulL1 avatar May 23 '15 04:05 PaulL1