Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 4ae831f

Browse files
Ghislain BeaulacGhislain Beaulac
authored andcommitted
feat(sorters): add a new SortDirectionNumber interface
- to make it easier to declare/use a Sorters
1 parent edea2ef commit 4ae831f

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/app/examples/grid-grouping.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, Injectable, OnInit, OnDestroy } from '@angular/core';
2-
import { Aggregators, Column, ExportService, FieldType, Formatter, Formatters, GridOption, Sorters } from './../modules/angular-slickgrid';
2+
import { Aggregators, Column, ExportService, FieldType, Formatter, Formatters, GridOption, SortDirectionNumber, Sorters } from './../modules/angular-slickgrid';
33
import { Subscription } from 'rxjs/Subscription';
44

55
@Injectable()
@@ -127,9 +127,7 @@ export class GridGroupingComponent implements OnInit, OnDestroy {
127127
new Aggregators.avg('percentComplete'),
128128
new Aggregators.sum('cost')
129129
],
130-
comparer: (a, b) => {
131-
return Sorters.numeric(a.value, b.value, 1);
132-
},
130+
comparer: (a, b) => Sorters.numeric(a.value, b.value, SortDirectionNumber.asc),
133131
aggregateCollapsed: false,
134132
lazyTotalsCalculation: true
135133
});

src/app/modules/angular-slickgrid/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,6 @@ export * from './slickEvent.interface';
6868
export * from './sortChanged.interface';
6969
export * from './sortChangedArgs.interface';
7070
export * from './sortDirection.enum';
71+
export * from './sortDirectionNumber.enum';
7172
export * from './sortDirectionString';
7273
export * from './sorter.interface';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export enum SortDirectionNumber {
2+
asc = 1,
3+
desc = -1,
4+
neutral = 0,
5+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export type Sorter = (value1: any, value2: any, sortDirection: number) => number;
1+
import { SortDirectionNumber } from './sortDirectionNumber.enum';
2+
3+
export type Sorter = (value1: any, value2: any, sortDirection: SortDirectionNumber) => number;

src/app/modules/angular-slickgrid/services/sort.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SortDirectionNumber } from './../models/sortDirectionNumber.enum';
12
import { castToPromise } from './utilities';
23
import { Column, FieldType, GridOption, SlickEvent, SortChanged, SortDirection, CurrentSorter, CellArgs, SortDirectionString } from './../models/index';
34
import { sortByFieldType } from '../sorters/sorterUtilities';
@@ -149,13 +150,13 @@ export class SortService {
149150
for (let i = 0, l = sortColumns.length; i < l; i++) {
150151
const columnSortObj = sortColumns[i];
151152
if (columnSortObj && columnSortObj.sortCol) {
152-
const sortDirection = columnSortObj.sortAsc ? 1 : -1;
153+
const sortDirection = columnSortObj.sortAsc ? SortDirectionNumber.asc : SortDirectionNumber.desc;
153154
const sortField = columnSortObj.sortCol.queryField || columnSortObj.sortCol.queryFieldFilter || columnSortObj.sortCol.field;
154155
const fieldType = columnSortObj.sortCol.type || FieldType.string;
155156
const value1 = dataRow1[sortField];
156157
const value2 = dataRow2[sortField];
157158
const sortResult = sortByFieldType(value1, value2, fieldType, sortDirection);
158-
if (sortResult !== 0) {
159+
if (sortResult !== SortDirectionNumber.neutral) {
159160
return sortResult;
160161
}
161162
}

0 commit comments

Comments
 (0)