File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 674
674
var existingGrouping = service . getGrouping ( grid ) ;
675
675
column . grouping . groupPriority = existingGrouping . grouping . length ;
676
676
677
+ // save sort in order to restore it when column is ungrouped
678
+ column . previousSort = angular . copy ( column . sort ) ;
679
+
677
680
// add sort if not present
678
681
if ( ! column . sort ) {
679
682
column . sort = { direction : uiGridConstants . ASC } ;
716
719
delete column . treeAggregation ;
717
720
delete column . customTreeAggregationFinalizer ;
718
721
722
+ if ( column . previousSort ) {
723
+ column . sort = column . previousSort ;
724
+ delete column . previousSort ;
725
+ }
726
+
719
727
service . tidyPriorities ( grid ) ;
720
728
721
729
grid . api . grouping . raise . groupingChanged ( column ) ;
730
+ grid . api . core . raise . sortChanged ( grid , grid . getColumnSorting ( ) ) ;
722
731
723
732
grid . queueGridRefresh ( ) ;
724
733
} ,
Original file line number Diff line number Diff line change @@ -101,6 +101,30 @@ describe('ui.grid.grouping uiGridGroupingService', function () {
101
101
} ) ;
102
102
103
103
104
+ describe ( 'groupColumn' , function ( ) {
105
+ it ( 'saves previous sort state' , function ( ) {
106
+ grid . columns [ 1 ] . sort = { priority : 42 , direction : 'foo' } ;
107
+ uiGridGroupingService . groupColumn ( grid , grid . columns [ 1 ] ) ;
108
+ expect ( grid . columns [ 1 ] . previousSort . priority ) . toBe ( 42 ) ;
109
+ expect ( grid . columns [ 1 ] . previousSort . direction ) . toBe ( 'foo' ) ;
110
+ } ) ;
111
+ } ) ;
112
+
113
+ describe ( 'ungroupColumn' , function ( ) {
114
+ it ( 'restores previuosly restored state if there is one' , function ( ) {
115
+ grid . columns [ 1 ] . previousSort = { direction : 'bar' } ;
116
+ uiGridGroupingService . ungroupColumn ( grid , grid . columns [ 1 ] ) ;
117
+ expect ( grid . columns [ 1 ] . sort . direction ) . toBe ( 'bar' ) ;
118
+ } ) ;
119
+
120
+ it ( 'should remove previous sort prop from column object after column sort is restored' , function ( ) {
121
+ grid . columns [ 1 ] . previousSort = { direction : 'bar' } ;
122
+ uiGridGroupingService . ungroupColumn ( grid , grid . columns [ 1 ] ) ;
123
+ expect ( grid . columns [ 1 ] . previousSort ) . toBeUndefined ( ) ;
124
+ } ) ;
125
+ } ) ;
126
+
127
+
104
128
describe ( 'groupRows' , function ( ) {
105
129
beforeEach ( function ( ) {
106
130
spyOn ( gridClassFactory , 'rowTemplateAssigner' ) . and . callFake ( function ( ) { } ) ;
You can’t perform that action at this time.
0 commit comments