-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
19 changed files
with
174 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
projects/igniteui-angular/src/lib/data-operations/groupby-state.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { IGroupByExpandState } from './groupby-expand-state.interface'; | ||
import { ISortingExpression } from './sorting-expression.interface'; | ||
import { ISortingStrategy} from './sorting-strategy'; | ||
import { IGroupingExpression } from './grouping-expression.interface'; | ||
|
||
export interface IGroupingState { | ||
expressions: ISortingExpression[]; | ||
expressions: IGroupingExpression[]; | ||
expansion: IGroupByExpandState[]; | ||
defaultExpanded: boolean; | ||
} |
39 changes: 39 additions & 0 deletions
39
projects/igniteui-angular/src/lib/data-operations/groupby-strategy.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { DataGenerator } from './test-util/data-generator'; | ||
import { DefaultSortingStrategy } from './sorting-strategy'; | ||
import { SortingDirection } from './sorting-expression.interface'; | ||
import { IGroupByRecord } from './groupby-record.interface'; | ||
import { IgxGrouping } from './grouping-strategy'; | ||
|
||
describe('Unit testing GroupingStrategy', () => { | ||
let dataGenerator: DataGenerator; | ||
let data: object[]; | ||
const grouping = new IgxGrouping(); | ||
beforeEach(() => { | ||
dataGenerator = new DataGenerator(); | ||
data = dataGenerator.data; | ||
}); | ||
|
||
it('should group by a field', () => { | ||
const expr = [{ | ||
dir: SortingDirection.Asc, | ||
fieldName: 'boolean', | ||
ignoreCase: false, | ||
strategy: DefaultSortingStrategy.instance() | ||
}]; | ||
const res = grouping.sort(data, expr); | ||
const gres = grouping.groupBy(res, expr); | ||
expect(dataGenerator.getValuesForColumn(gres.data, 'boolean')) | ||
.toEqual([false, false, false, true, true]); | ||
const group1: IGroupByRecord = gres.metadata[0]; | ||
const group2: IGroupByRecord = gres.metadata[3]; | ||
expect(gres.metadata[1]).toEqual(group1); | ||
expect(gres.metadata[2]).toEqual(group1); | ||
expect(gres.metadata[4]).toEqual(group2); | ||
expect(group1.level).toEqual(0); | ||
expect(group2.level).toEqual(0); | ||
expect(group1.records).toEqual(gres.data.slice(0, 3)); | ||
expect(group2.records).toEqual(gres.data.slice(3, 5)); | ||
expect(group1.value).toEqual(false); | ||
expect(group2.value).toEqual(true); | ||
}); | ||
}); |
5 changes: 5 additions & 0 deletions
5
projects/igniteui-angular/src/lib/data-operations/grouping-expression.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ISortingExpression } from './sorting-expression.interface'; | ||
|
||
export interface IGroupingExpression extends ISortingExpression { | ||
groupingComparer?: (a: any, b: any) => number; | ||
} |
20 changes: 20 additions & 0 deletions
20
projects/igniteui-angular/src/lib/data-operations/grouping-strategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { IGroupByRecord } from './groupby-record.interface'; | ||
import { ISortingExpression } from './sorting-expression.interface'; | ||
import { IgxSorting } from './sorting-strategy'; | ||
|
||
export interface IGroupByResult { | ||
data: any[]; | ||
metadata: IGroupByRecord[]; | ||
} | ||
|
||
export class IgxGrouping extends IgxSorting { | ||
public groupBy(data: any[], expressions: ISortingExpression[]): IGroupByResult { | ||
const metadata: IGroupByRecord[] = []; | ||
const grouping = this.groupDataRecursive(data, expressions, 0, null, metadata); | ||
return { | ||
data: grouping, | ||
metadata: metadata | ||
}; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.