@@ -20,6 +20,7 @@ import { GridSelectionFunctions, GridFunctions } from '../../test-utils/grid-fun
2020import { GridSelectionMode } from '../common/enums' ;
2121import { ControlsFunction } from '../../test-utils/controls-functions.spec' ;
2222import { IGroupingExpression } from '../../data-operations/grouping-expression.interface' ;
23+ import { IgxGrouping } from '../../data-operations/grouping-strategy' ;
2324
2425describe ( 'IgxGrid - GroupBy #grid' , ( ) => {
2526
@@ -602,6 +603,21 @@ describe('IgxGrid - GroupBy #grid', () => {
602603 expect ( grid . groupingExpressionsChange . emit ) . toHaveBeenCalledTimes ( 0 ) ;
603604 } ) ) ;
604605
606+ it ( 'should group unbound column with custom grouping strategy' , fakeAsync ( ( ) => {
607+ const fix = TestBed . createComponent ( GroupableGridComponent ) ;
608+ fix . componentInstance . data . forEach ( ( r , i ) => {
609+ r [ 'fieldValue1' ] = Math . floor ( i / 3 ) ;
610+ r [ 'fieldValue2' ] = Math . floor ( i / 4 ) ;
611+ } ) ;
612+ fix . detectChanges ( ) ;
613+ fix . componentInstance . instance . groupBy ( {
614+ fieldName : 'UnboundField' , dir : SortingDirection . Desc , ignoreCase : false
615+ } ) ;
616+ fix . detectChanges ( ) ;
617+ const groupRows = fix . componentInstance . instance . groupsRowList . toArray ( ) ;
618+ expect ( groupRows . length ) . toEqual ( 4 ) ;
619+ } ) ) ;
620+
605621 // GroupBy + Sorting integration
606622 it ( 'should apply sorting on each group\'s records when non-grouped column is sorted.' , fakeAsync ( ( ) => {
607623 const fix = TestBed . createComponent ( DefaultGridComponent ) ;
@@ -1848,36 +1864,36 @@ describe('IgxGrid - GroupBy #grid', () => {
18481864 } ) ) ;
18491865
18501866 it ( 'Should have the correct properties in the custom row selector template' , fakeAsync ( ( ) => {
1851- const fix = TestBed . createComponent ( GridGroupByRowCustomSelectorsComponent ) ;
1852- const grid = fix . componentInstance . instance ;
1853- fix . componentInstance . width = '1200px' ;
1854- tick ( ) ;
1855- grid . columnWidth = '200px' ;
1856- tick ( ) ;
1857- grid . rowSelection = GridSelectionMode . multiple ;
1858- tick ( ) ;
1859- fix . detectChanges ( ) ;
1867+ const fix = TestBed . createComponent ( GridGroupByRowCustomSelectorsComponent ) ;
1868+ const grid = fix . componentInstance . instance ;
1869+ fix . componentInstance . width = '1200px' ;
1870+ tick ( ) ;
1871+ grid . columnWidth = '200px' ;
1872+ tick ( ) ;
1873+ grid . rowSelection = GridSelectionMode . multiple ;
1874+ tick ( ) ;
1875+ fix . detectChanges ( ) ;
18601876
1861- grid . groupBy ( {
1862- fieldName : 'ProductName' , dir : SortingDirection . Desc , ignoreCase : false
1863- } ) ;
1864- tick ( ) ;
1865- fix . detectChanges ( ) ;
1877+ grid . groupBy ( {
1878+ fieldName : 'ProductName' , dir : SortingDirection . Desc , ignoreCase : false
1879+ } ) ;
1880+ tick ( ) ;
1881+ fix . detectChanges ( ) ;
18661882
1867- const grRow = grid . groupsRowList . toArray ( ) [ 0 ] ;
1868- const contextSelect = { selectedCount : 0 , totalCount : 2 , groupRow : grid . groupsRowList . toArray ( ) [ 0 ] . groupRow } ;
1869- const contextUnselect = { selectedCount : 2 , totalCount : 2 , groupRow : grid . groupsRowList . toArray ( ) [ 0 ] . groupRow } ;
1883+ const grRow = grid . groupsRowList . toArray ( ) [ 0 ] ;
1884+ const contextSelect = { selectedCount : 0 , totalCount : 2 , groupRow : grid . groupsRowList . toArray ( ) [ 0 ] . groupRow } ;
1885+ const contextUnselect = { selectedCount : 2 , totalCount : 2 , groupRow : grid . groupsRowList . toArray ( ) [ 0 ] . groupRow } ;
18701886
1871- spyOn ( fix . componentInstance , 'onGroupByRowClick' ) . and . callThrough ( ) ;
1887+ spyOn ( fix . componentInstance , 'onGroupByRowClick' ) . and . callThrough ( ) ;
18721888
1873- grRow . nativeElement . querySelector ( '.igx-checkbox__composite' ) . click ( ) ;
1874- fix . detectChanges ( ) ;
1875- expect ( fix . componentInstance . onGroupByRowClick ) . toHaveBeenCalledWith ( fix . componentInstance . groupByRowClick , contextSelect ) ;
1889+ grRow . nativeElement . querySelector ( '.igx-checkbox__composite' ) . click ( ) ;
1890+ fix . detectChanges ( ) ;
1891+ expect ( fix . componentInstance . onGroupByRowClick ) . toHaveBeenCalledWith ( fix . componentInstance . groupByRowClick , contextSelect ) ;
18761892
1877- grRow . nativeElement . querySelector ( '.igx-checkbox__composite' ) . click ( ) ;
1878- fix . detectChanges ( ) ;
1879- expect ( fix . componentInstance . onGroupByRowClick ) . toHaveBeenCalledWith ( fix . componentInstance . groupByRowClick , contextUnselect ) ;
1880- } ) ) ;
1893+ grRow . nativeElement . querySelector ( '.igx-checkbox__composite' ) . click ( ) ;
1894+ fix . detectChanges ( ) ;
1895+ expect ( fix . componentInstance . onGroupByRowClick ) . toHaveBeenCalledWith ( fix . componentInstance . groupByRowClick , contextUnselect ) ;
1896+ } ) ) ;
18811897
18821898 // GroupBy + Resizing
18831899 it ( 'should retain same size for group row after a column is resized.' , fakeAsync ( ( ) => {
@@ -3488,19 +3504,42 @@ export class DefaultGridComponent extends DataParent {
34883504 }
34893505}
34903506
3507+ const formatUnboundValueFunction = ( rowData : any | undefined ) : string | undefined => rowData . fieldValue1 + ' ' + rowData . fieldValue2 ;
3508+
3509+
3510+ class MySortingStrategy extends IgxGrouping {
3511+ protected getFieldValue (
3512+ obj : any ,
3513+ key : string ,
3514+ isDate = false ,
3515+ isTime = false
3516+ ) : unknown {
3517+ if ( key !== 'UnboundField' ) {
3518+ return super . getFieldValue ( obj , key , isDate , isTime ) ;
3519+ }
3520+
3521+ return formatUnboundValueFunction ( obj ) ;
3522+ }
3523+ }
3524+
34913525@Component ( {
34923526 template : `
34933527 <igx-grid
34943528 [width]='width'
34953529 [height]='height'
3496- [data]="data">
3530+ [data]="data"
3531+ [sortStrategy]="sortStrategy"
3532+ [groupStrategy]="groupStrategy">
34973533 <igx-column [field]="'ID'" [header]="'ID'" [width]="200" [groupable]="true" [hasSummary]="false"></igx-column>
34983534 <igx-column [field]="'ReleaseDate'" [header]="'ReleaseDate'" [width]="200" [groupable]="true" [hasSummary]="false"
34993535 dataType="date"></igx-column>
35003536 <igx-column [field]="'Downloads'" [header]="'Downloads'" [width]="200" [groupable]="true" [hasSummary]="false"
35013537 dataType="number"></igx-column>
35023538 <igx-column [field]="'ProductName'" [header]="'ProductName'" [width]="200" [groupable]="true" [hasSummary]="false"></igx-column>
35033539 <igx-column [field]="'Released'" [header]="'Released'" [width]="200" [groupable]="true" [hasSummary]="false"></igx-column>
3540+ <igx-column [field]="'UnboundField'" [header]="'Unbound Value'" [width]="200" [dataType]="'string'"
3541+ [sortable]="true" [groupable]="true" [formatter]="formatUnboundValue">
3542+ </igx-column>
35043543 <igx-paginator></igx-paginator>
35053544 </igx-grid>
35063545 `
@@ -3511,6 +3550,13 @@ export class GroupableGridComponent extends DataParent {
35113550
35123551 public width = '800px' ;
35133552 public height = '700px' ;
3553+
3554+ public sortStrategy = new MySortingStrategy ( ) ;
3555+ public groupStrategy = this . sortStrategy ;
3556+
3557+ public formatUnboundValue ( value : string , rowData : any | undefined ) : string | undefined {
3558+ return formatUnboundValueFunction ( rowData ) ;
3559+ }
35143560}
35153561
35163562@Component ( {
0 commit comments