Skip to content

Commit d30b1ad

Browse files
committed
fix(grouping): Grouping now raises a sort changed event
Grouping was not calling sort changed which meant that external sorting with grouping wasn't working. - Adds a call to raise a `sortChanged` event when grouping. - Additionally adds a test to grouping to ensure that this event is raised. Closes #4155
1 parent 213769e commit d30b1ad

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

Diff for: src/features/grouping/js/grouping.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -681,13 +681,13 @@
681681
column.sort.direction = uiGridConstants.ASC;
682682
}
683683

684-
service.tidyPriorities( grid );
685-
686684
column.treeAggregation = { type: uiGridGroupingConstants.aggregation.COUNT, source: 'grouping' };
687685
column.treeAggregationFn = uiGridTreeBaseService.nativeAggregations()[uiGridGroupingConstants.aggregation.COUNT].aggregationFn;
688686
column.treeAggregationFinalizerFn = service.groupedFinalizerFn;
689687

690688
grid.api.grouping.raise.groupingChanged(column);
689+
// This indirectly calls service.tidyPriorities( grid );
690+
grid.api.core.raise.sortChanged(grid, grid.getColumnSorting());
691691

692692
grid.queueGridRefresh();
693693
},

Diff for: src/features/grouping/test/grouping.spec.js

+45
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,51 @@ describe('ui.grid.grouping uiGridGroupingService', function () {
482482
});
483483
});
484484

485+
it('sorts', function(){
486+
grid.grouping.groupingHeaderCache = {
487+
male: {
488+
row: { treeNode: { state: 'collapsed' } },
489+
children: {
490+
22: { row: { treeNode: { state: 'expanded' } }, children: {} },
491+
39: { row: { treeNode: { state: 'collapsed' } }, children: {} }
492+
}
493+
},
494+
female: {
495+
row: { treeNode: { state: 'expanded' } },
496+
children: {
497+
23: { row: { treeNode: { state: 'collapsed' } }, children: {} },
498+
38: { row: { treeNode: { state: 'expanded' } }, children: {} }
499+
}
500+
}
501+
};
502+
503+
spyOn(grid.api.core.raise, 'sortChanged').andCallThrough();
504+
505+
grid.api.grouping.setGrouping({
506+
grouping: [
507+
{ field: 'col3', colName: 'col3', groupPriority: 0 },
508+
{ field: 'col2', colName: 'col2', groupPriority: 1 }
509+
],
510+
aggregations: [
511+
{ field: 'col1', colName: 'col1', aggregation: { type: uiGridGroupingConstants.aggregation.COUNT } }
512+
],
513+
rowExpandedStates: {
514+
male: { state: 'expanded', children: {
515+
22: { state: 'collapsed' },
516+
38: { state: 'expanded' }
517+
} },
518+
female: { state: 'expanded', children: {
519+
23: { state: 'expanded' },
520+
39: { state: 'collapsed' }
521+
} }
522+
}
523+
});
524+
525+
// Should call sort change twice because we are grouping by two columns
526+
expect(grid.api.core.raise.sortChanged.calls.length).toEqual(2);
527+
528+
});
529+
485530
});
486531

487532

0 commit comments

Comments
 (0)