Skip to content

Commit 3ddcff8

Browse files
authored
Merge pull request #10286 from IgniteUI/vkombov/feat-10125-master
feat(combo): expose input to set groups sorting order
2 parents 9268abc + 06442af commit 3ddcff8

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ All notable changes for each version of this project will be documented in this
99
- Exporter services are no longer required to be provided in the application since they are now injected on a root level.
1010
- `IgxGridToolbarPinningComponent`, `IgxGridToolbarHidingComponent`
1111
- Exposed new input `buttonText` which sets the text that is displayed inside the dropdown button in the toolbar.
12+
- `IgxCombo`
13+
- Added `groupSortingDirection` input, which allows you to set groups sorting order.
1214

1315
### General
1416

@@ -3657,3 +3659,4 @@ export class IgxCustomFilteringOperand extends IgxFilteringOperand {
36573659
- `IgxDraggableDirective` moved inside `../directives/dragdrop/` folder
36583660
- `IgxRippleDirective` moved inside `../directives/ripple/` folder
36593661
- Folder `"./navigation/nav-service"` renamed to `"./navigation/nav.service"`
3662+

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:groupSortingDirection;
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { AbsoluteScrollStrategy, ConnectedPositioningStrategy } from '../service
2828
import { IgxSelectionAPIService } from '../core/selection';
2929
import { IgxIconService } from '../icon/public_api';
3030
import { IBaseCancelableBrowserEventArgs } from '../core/utils';
31+
import { SortingDirection } from '../data-operations/sorting-expression.interface';
3132

3233
const CSS_CLASS_COMBO = 'igx-combo';
3334
const CSS_CLASS_COMBO_DROPDOWN = 'igx-combo__drop-down';
@@ -2172,6 +2173,17 @@ describe('igxCombo', () => {
21722173
expect(combo.dropdown.headers.length).toEqual(1);
21732174
expect(combo.dropdown.headers[0].element.nativeElement.innerText).toEqual(fallBackGroup);
21742175
});
2176+
it('should sort groups correctly', () => {
2177+
combo.groupSortingDirection = SortingDirection.Asc;
2178+
combo.toggle();
2179+
fixture.detectChanges();
2180+
expect(combo.dropdown.headers[0].element.nativeElement.innerText).toEqual('East North Central');
2181+
2182+
combo.groupSortingDirection = SortingDirection.Desc;
2183+
combo.toggle();
2184+
fixture.detectChanges();
2185+
expect(combo.dropdown.headers[0].element.nativeElement.innerText).toEqual('West South Cent');
2186+
});
21752187
});
21762188
describe('Filtering tests: ', () => {
21772189
configureTestSuite();

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { EditorProvider } from '../core/edit-provider';
4040
import { IgxInputState, IgxInputDirective } from '../directives/input/input.directive';
4141
import { IgxInputGroupType, IGX_INPUT_GROUP_TYPE } from '../input-group/public_api';
4242
import { caseSensitive } from '@igniteui/material-icons-extended';
43+
import { SortingDirection } from '../data-operations/sorting-expression.interface';
4344

4445
/**
4546
* @hidden
@@ -774,6 +775,25 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
774775
@Input()
775776
public filterable = true;
776777

778+
/**
779+
* An @Input property that sets groups sorting order.
780+
*
781+
* @example
782+
* ```html
783+
* <igx-combo [groupSortingDirection]="groupSortingDirection"></igx-combo>
784+
* ```
785+
* ```typescript
786+
* public groupSortingDirection = SortingDirection.Asc;
787+
* ```
788+
*/
789+
@Input()
790+
public get groupSortingDirection(): SortingDirection {
791+
return this._groupSortingDirection;
792+
}
793+
public set groupSortingDirection(val: SortingDirection) {
794+
this._groupSortingDirection = val;
795+
}
796+
777797
/**
778798
* An @Input property that set aria-labelledby attribute
779799
* ```html
@@ -906,6 +926,7 @@ export class IgxComboComponent extends DisplayDensityBase implements IgxComboBas
906926
private _overlaySettings: OverlaySettings;
907927
private _value = '';
908928
private _valid = IgxComboState.INITIAL;
929+
private _groupSortingDirection: SortingDirection = SortingDirection.Asc;
909930

910931
constructor(
911932
protected elementRef: ElementRef,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ 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: SortingDirection) {
4848
this.combo.filteredData = collection;
4949
if ((!groupKey && groupKey !== 0) || !collection.length) {
5050
return collection;
5151
}
5252
const sorted = DataUtil.sort(cloneArray(collection), [{
5353
fieldName: groupKey,
54-
dir: SortingDirection.Asc,
54+
dir: sortingDirection,
5555
ignoreCase: true,
5656
strategy: DefaultSortingStrategy.instance()
5757
}]);

0 commit comments

Comments
 (0)