From d632063647787dae2d6641933d44c74887b7ecd9 Mon Sep 17 00:00:00 2001 From: Akshit Singhal Date: Thu, 8 Oct 2015 15:15:46 +0530 Subject: [PATCH] fix(grouping): When 'field' in columnDef is referred to some javascript object than a primitive type. Grouping fails when 'field' in columnDef is referred to some javascript object than a primitive type. Resolves issue [4493](https://github.com/angular-ui/ui-grid/issues/4493) --- src/features/grouping/js/grouping.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/features/grouping/js/grouping.js b/src/features/grouping/js/grouping.js index 2a0d03179f..2c832aa749 100644 --- a/src/features/grouping/js/grouping.js +++ b/src/features/grouping/js/grouping.js @@ -1050,16 +1050,24 @@ newDisplayValue = grid.options.groupingNullLabel; } + var getKeyAsValueForCacheMap = function(key) { + if (angular.isObject(key)) { + return JSON.stringify(key); + } else { + return key; + } + }; + var cacheItem = grid.grouping.oldGroupingHeaderCache; for ( var i = 0; i < stateIndex; i++ ){ - if ( cacheItem && cacheItem[processingState[i].currentValue] ){ - cacheItem = cacheItem[processingState[i].currentValue].children; + if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)] ){ + cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children; } } var headerRow; - if ( cacheItem && cacheItem[newValue]){ - headerRow = cacheItem[newValue].row; + if ( cacheItem && cacheItem[getKeyAsValueForCacheMap(newValue)]){ + headerRow = cacheItem[getKeyAsValueForCacheMap(newValue)].row; headerRow.entity = {}; } else { headerRow = new GridRow( {}, null, grid ); @@ -1086,9 +1094,9 @@ // add our new header row to the cache cacheItem = grid.grouping.groupingHeaderCache; for ( i = 0; i < stateIndex; i++ ){ - cacheItem = cacheItem[processingState[i].currentValue].children; + cacheItem = cacheItem[getKeyAsValueForCacheMap(processingState[i].currentValue)].children; } - cacheItem[newValue] = { row: headerRow, children: {} }; + cacheItem[getKeyAsValueForCacheMap(newValue)] = { row: headerRow, children: {} }; },