@@ -118,5 +118,106 @@ describe('Basic IgxPivotGrid #pivotGrid', () => {
118118 const expected = [ 'USA' ] ;
119119 expect ( colHeaders ) . toEqual ( expected ) ;
120120 } ) ;
121+
122+ it ( 'should sort on column for single row dimension.' , ( ) => {
123+ const pivotGrid = fixture . componentInstance . pivotGrid ;
124+ const headerCell = GridFunctions . getColumnHeader ( 'USA-UnitsSold' , fixture ) ;
125+
126+ // sort asc
127+ GridFunctions . clickHeaderSortIcon ( headerCell ) ;
128+ fixture . detectChanges ( ) ;
129+ expect ( pivotGrid . sortingExpressions . length ) . toBe ( 1 ) ;
130+ let expectedOrder = [ 829 , undefined , 240 , 293 , 296 ] ;
131+ let columnValues = pivotGrid . dataView . map ( x => x [ 'USA-UnitsSold' ] ) ;
132+ expect ( columnValues ) . toEqual ( expectedOrder ) ;
133+
134+ // sort desc
135+ GridFunctions . clickHeaderSortIcon ( headerCell ) ;
136+ fixture . detectChanges ( ) ;
137+ expect ( pivotGrid . sortingExpressions . length ) . toBe ( 1 ) ;
138+ expectedOrder = [ 829 , 296 , 293 , 240 , undefined ] ;
139+ columnValues = pivotGrid . dataView . map ( x => x [ 'USA-UnitsSold' ] ) ;
140+ expect ( columnValues ) . toEqual ( expectedOrder ) ;
141+
142+ // remove sort
143+ GridFunctions . clickHeaderSortIcon ( headerCell ) ;
144+ fixture . detectChanges ( ) ;
145+ expect ( pivotGrid . sortingExpressions . length ) . toBe ( 0 ) ;
146+ expectedOrder = [ 829 , 296 , undefined , 293 , 240 ] ;
147+ columnValues = pivotGrid . dataView . map ( x => x [ 'USA-UnitsSold' ] ) ;
148+ expect ( columnValues ) . toEqual ( expectedOrder ) ;
149+ } ) ;
150+
151+ it ( 'should sort on column for all sibling dimensions.' , ( ) => {
152+ const pivotGrid = fixture . componentInstance . pivotGrid ;
153+ pivotGrid . height = '1500px' ;
154+ pivotGrid . pivotConfiguration . rows = [
155+ {
156+ memberName : 'ProductCategory' ,
157+ enabled : true
158+ } ,
159+ {
160+ memberName : 'SellerName' ,
161+ enabled : true
162+ }
163+ ] ;
164+ // add a bit more data to sort.
165+ pivotGrid . data = [
166+ {
167+ ProductCategory : 'Clothing' , UnitPrice : 12.81 , SellerName : 'Stanley' ,
168+ Country : 'Bulgaria' , Date : '01/01/2021' , UnitsSold : 282
169+ } ,
170+ {
171+ ProductCategory : 'Clothing' , UnitPrice : 49.57 , SellerName : 'Elisa' ,
172+ Country : 'USA' , Date : '01/05/2019' , UnitsSold : 296
173+ } ,
174+ {
175+ ProductCategory : 'Bikes' , UnitPrice : 3.56 , SellerName : 'Lydia' ,
176+ Country : 'Uruguay' , Date : '01/06/2020' , UnitsSold : 68
177+ } ,
178+ {
179+ ProductCategory : 'Accessories' , UnitPrice : 85.58 , SellerName : 'David' ,
180+ Country : 'USA' , Date : '04/07/2021' , UnitsSold : 293
181+ } ,
182+ {
183+ ProductCategory : 'Components' , UnitPrice : 18.13 , SellerName : 'John' ,
184+ Country : 'USA' , Date : '12/08/2021' , UnitsSold : 240
185+ } ,
186+ {
187+ ProductCategory : 'Clothing' , UnitPrice : 68.33 , SellerName : 'Larry' ,
188+ Country : 'Uruguay' , Date : '05/12/2020' , UnitsSold : 456
189+ } ,
190+ {
191+ ProductCategory : 'Clothing' , UnitPrice : 16.05 , SellerName : 'Walter' ,
192+ Country : 'Bulgaria' , Date : '02/19/2020' , UnitsSold : 492
193+ } ,
194+ {
195+ ProductCategory : 'Clothing' , UnitPrice : 16.05 , SellerName : 'Elisa' ,
196+ Country : 'Bulgaria' , Date : '02/19/2020' , UnitsSold : 267
197+ } ,
198+ {
199+ ProductCategory : 'Clothing' , UnitPrice : 16.05 , SellerName : 'Larry' ,
200+ Country : 'Bulgaria' , Date : '02/19/2020' , UnitsSold : 100
201+ }
202+ ] ;
203+ pivotGrid . pipeTrigger ++ ;
204+ fixture . detectChanges ( ) ;
205+ const headerCell = GridFunctions . getColumnHeader ( 'Bulgaria-UnitsSold' , fixture ) ;
206+ // sort asc
207+ GridFunctions . clickHeaderSortIcon ( headerCell ) ;
208+ fixture . detectChanges ( ) ;
209+ expect ( pivotGrid . sortingExpressions . length ) . toBe ( 1 ) ;
210+ let expectedOrder = [ undefined , undefined , undefined , 100 , 267 , 282 , 492 ] ;
211+ let columnValues = pivotGrid . dataView . map ( x => x [ 'Bulgaria-UnitsSold' ] ) ;
212+ expect ( columnValues ) . toEqual ( expectedOrder ) ;
213+
214+ // sort desc
215+ GridFunctions . clickHeaderSortIcon ( headerCell ) ;
216+ fixture . detectChanges ( ) ;
217+ expect ( pivotGrid . sortingExpressions . length ) . toBe ( 1 ) ;
218+ expectedOrder = [ 492 , 282 , 267 , 100 , undefined , undefined , undefined ] ;
219+ columnValues = pivotGrid . dataView . map ( x => x [ 'Bulgaria-UnitsSold' ] ) ;
220+ expect ( columnValues ) . toEqual ( expectedOrder ) ;
221+ } ) ;
121222 } ) ;
122223} ) ;
0 commit comments