Skip to content

Commit f7f26e4

Browse files
committed
feat(combo): expose input to set groups sorting order
1 parent 5687ab5 commit f7f26e4

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ All notable changes for each version of this project will be documented in this
77
### New Features
88
- `IgxCsvExporterService`, `IgxExcelExporterService`
99
- Exporter services are no longer required to be provided in the application since they are now injected on a root level.
10+
- `IgxCombo`
11+
- Added `groupsSortingDirection` input, which allows you to set groups sorting order.
1012

1113
### General
1214

projects/igniteui-angular/src/lib/combo/combo.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
[tabindex]="dropdown.collapsed ? -1 : 0" role="listbox" [attr.id]="dropdown.id">
5353
<igx-combo-item role="option" [itemHeight]='itemHeight' *igxFor="let item of data
5454
| comboFiltering:filterValue:displayKey:filterable:filteringOptions
55-
| comboGrouping:groupKey:valueKey;
55+
| comboGrouping:groupKey:valueKey:groupsSortingDirection;
5656
index as rowIndex; containerSize: itemsMaxHeight; scrollOrientation: 'vertical'; itemSize: itemHeight"
5757
[value]="item" [isHeader]="item.isHeader" [index]="rowIndex">
5858
<ng-container *ngIf="item.isHeader">

projects/igniteui-angular/src/lib/combo/combo.component.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,17 @@ describe('igxCombo', () => {
21722172
expect(combo.dropdown.headers.length).toEqual(1);
21732173
expect(combo.dropdown.headers[0].element.nativeElement.innerText).toEqual(fallBackGroup);
21742174
});
2175+
it('should sort groups correctly', () => {
2176+
combo.groupsSortingDirection = 'ascending';
2177+
combo.toggle();
2178+
fixture.detectChanges();
2179+
expect(combo.dropdown.headers[0].element.nativeElement.innerText).toEqual('East North Central');
2180+
2181+
combo.groupsSortingDirection = 'descending';
2182+
combo.toggle();
2183+
fixture.detectChanges();
2184+
expect(combo.dropdown.headers[0].element.nativeElement.innerText).toEqual('West South Cent');
2185+
});
21752186
});
21762187
describe('Filtering tests: ', () => {
21772188
configureTestSuite();

projects/igniteui-angular/src/lib/combo/combo.component.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import {
1616
import { FormsModule, ReactiveFormsModule, ControlValueAccessor, NG_VALUE_ACCESSOR, NgControl, AbstractControl } from '@angular/forms';
1717
import { IgxCheckboxModule } from '../checkbox/checkbox.component';
1818
import { IgxSelectionAPIService } from '../core/selection';
19-
import { cloneArray, IBaseEventArgs, IBaseCancelableBrowserEventArgs, IBaseCancelableEventArgs, CancelableEventArgs } from '../core/utils';
19+
import {
20+
cloneArray, IBaseEventArgs, IBaseCancelableBrowserEventArgs, IBaseCancelableEventArgs, CancelableEventArgs, mkenum
21+
} from '../core/utils';
2022
import { IgxStringFilteringOperand, IgxBooleanFilteringOperand } from '../data-operations/filtering-condition';
2123
import { FilteringLogic } from '../data-operations/filtering-expression.interface';
2224
import { IgxForOfModule, IForOfState, IgxForOfDirective } from '../directives/for-of/for_of.directive';
@@ -67,6 +69,16 @@ const ItemHeights = {
6769
*/
6870
const itemsInContainer = 10;
6971

72+
/**
73+
* @hidden
74+
*/
75+
export const GroupsSortingDirection = mkenum({
76+
ascending: 'ascending',
77+
descending: 'descending'
78+
});
79+
80+
export type GroupsSortingDirection = (typeof GroupsSortingDirection)[keyof typeof GroupsSortingDirection];
81+
7082
export enum IgxComboState {
7183
/**
7284
* Combo with initial state.
@@ -774,6 +786,20 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
774786
@Input()
775787
public filterable = true;
776788

789+
/**
790+
* An @Input property that sets groups sorting order. The default is `ascending`.
791+
* ```html
792+
* <igx-combo [groupsSortingDirection]="'ascending'">
793+
* ```
794+
*/
795+
@Input()
796+
public get groupsSortingDirection() {
797+
return this._groupsSortingDirection;
798+
}
799+
public set groupsSortingDirection(val: GroupsSortingDirection) {
800+
this._groupsSortingDirection = val;
801+
}
802+
777803
/**
778804
* An @Input property that set aria-labelledby attribute
779805
* ```html
@@ -906,6 +932,7 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
906932
private _overlaySettings: OverlaySettings;
907933
private _value = '';
908934
private _valid = IgxComboState.INITIAL;
935+
private _groupsSortingDirection: GroupsSortingDirection = GroupsSortingDirection.ascending;
909936

910937
constructor(
911938
protected elementRef: ElementRef,

projects/igniteui-angular/src/lib/combo/combo.pipes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DataUtil } from '../data-operations/data-util';
44
import { SortingDirection } from '../data-operations/sorting-expression.interface';
55
import { IGX_COMBO_COMPONENT, IgxComboBase } from './combo.common';
66
import { DefaultSortingStrategy } from '../data-operations/sorting-strategy';
7-
import { IComboFilteringOptions } from './combo.component';
7+
import { IComboFilteringOptions, GroupsSortingDirection } from './combo.component';
88

99

1010
/**
@@ -44,14 +44,15 @@ export class IgxComboGroupingPipe implements PipeTransform {
4444

4545
constructor(@Inject(IGX_COMBO_COMPONENT) public combo: IgxComboBase) { }
4646

47-
public transform(collection: any[], groupKey: any, valueKey: any) {
47+
public transform(collection: any[], groupKey: any, valueKey: any, sortingDirection: GroupsSortingDirection) {
4848
this.combo.filteredData = collection;
4949
if ((!groupKey && groupKey !== 0) || !collection.length) {
5050
return collection;
5151
}
52+
const dir: SortingDirection = sortingDirection === 'ascending' ? SortingDirection.Asc : SortingDirection.Desc;
5253
const sorted = DataUtil.sort(cloneArray(collection), [{
5354
fieldName: groupKey,
54-
dir: SortingDirection.Asc,
55+
dir,
5556
ignoreCase: true,
5657
strategy: DefaultSortingStrategy.instance()
5758
}]);

0 commit comments

Comments
 (0)