Skip to content

Commit 374693c

Browse files
authored
feat(sorting): Sort expression accepts type model for type narrowing (#12991)
1 parent 3d1bdc3 commit 374693c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ All notable changes for each version of this project will be documented in this
88
- All Ignite UI for Angular components are now exported as `standalone` components. The library still exports `NgModules`, which have been preserved for backward compatibility, but they no longer declare any of the Ignite UI for Angular components, instead they just import and export the `standalone` components. The `standalone` components are still in a preview stage. Some utility directive exports may change in the future and may be missing from the documentation in the initial release, hence the `preview` state of the feature.
99

1010
Now you can do:
11-
11+
1212
```typescript
1313
// IGX_GRID_DIRECTIVES exports all grid related components and directives
1414
import { IGX_GRID_DIRECTIVES } from 'igniteui-angular';
@@ -22,7 +22,7 @@ import { IGX_GRID_DIRECTIVES } from 'igniteui-angular';
2222
})
2323
```
2424

25-
or
25+
or
2626

2727
```typescript
2828
// Single import of only the <igx-grid> component.
@@ -65,6 +65,7 @@ import { IgxGridModule } from 'igniteui-angular';
6565
- `IgxGrid`, `IgxHierarchicalGrid`:
6666
- `totalItemCount` can now also be bound as `Input` in remote virtualization scenarios.
6767
- `rowExpandedIndicatorTemplate`, `rowCollapsedIndicatorTemplate`, `headerExpandedIndicatorTemplate`, `headerCollapsedIndicatorTemplate` can now also be bound as `Input` to provide templates for the row and header expand/collapse indicators respectively. This is in addition to the existing equivalent template directives to allow reuse.
68+
- `ISortingExpression` now accepts an optional generic type parameter for type narrowing of the `fieldName` property to keys of the data item, e.g. `ISortingExpression<MyDataItem>`
6869

6970
## 15.1.0
7071

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type KeyOfOrString<T, K = keyof T> = K extends keyof T ? K : string;

projects/igniteui-angular/src/lib/data-operations/sorting-strategy.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { KeyOfOrString } from '../core/types';
12
import { IBaseEventArgs } from '../core/utils';
23
import { GridType } from '../grids/common/grid.interface';
34

@@ -7,8 +8,8 @@ export enum SortingDirection {
78
Desc = 2
89
}
910

10-
export interface ISortingExpression extends IBaseEventArgs {
11-
fieldName: string;
11+
export interface ISortingExpression<T = any> extends IBaseEventArgs {
12+
fieldName: KeyOfOrString<T> & string;
1213
dir: SortingDirection;
1314
ignoreCase?: boolean;
1415
strategy?: ISortingStrategy;
@@ -124,4 +125,4 @@ export class GroupMemberCountSortingStrategy implements ISortingStrategy {
124125

125126
return reverse * (firstItemValuesLength - secondItemValuesLength);
126127
}
127-
}
128+
}

0 commit comments

Comments
 (0)