Skip to content

Commit

Permalink
feat(igxgrid sorting): Refactoring sorting strategy to per-column #2734
Browse files Browse the repository at this point in the history
  • Loading branch information
kdinev committed Nov 1, 2018
1 parent 6a7bf5d commit 3504e9e
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 521 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

66 changes: 7 additions & 59 deletions projects/igniteui-angular/src/lib/data-operations/data-util.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import {
IgxFilteringOperand,
IgxBooleanFilteringOperand,
IgxDateFilteringOperand,
IgxNumberFilteringOperand,
IgxStringFilteringOperand
} from './filtering-condition';
import { FilteringLogic, IFilteringExpression } from './filtering-expression.interface';
import { filteringStateDefaults, IFilteringState } from './filtering-state.interface';
import { FilteringStrategy, IFilteringStrategy } from './filtering-strategy';
import { IFilteringState } from './filtering-state.interface';

import { ISortingExpression, SortingDirection } from './sorting-expression.interface';
import { ISortingState, SortingStateDefaults } from './sorting-state.interface';
import { ISortingStrategy, SortingStrategy, IGroupByResult } from './sorting-strategy';
import { ISortingState } from './sorting-state.interface';
import { IGroupByResult, IgxSorting } from './sorting-strategy';

import { IPagingState, PagingError } from './paging-state.interface';

import { IDataState } from './data-state.interface';
import { IGroupByExpandState, IGroupByKey } from './groupby-expand-state.interface';
import { IGroupByRecord } from './groupby-record.interface';
import { IGroupingState } from './groupby-state.interface';
Expand All @@ -26,39 +15,16 @@ export enum DataType {
Boolean = 'boolean',
Date = 'date'
}

export class DataUtil {
public static mergeDefaultProperties(target: object, defaults: object) {
if (!defaults) {
return target;
}
if (!target) {
target = Object.assign({}, defaults);
return target;
}
Object
.keys(defaults)
.forEach((key) => {
if (target[key] === undefined && defaults[key] !== undefined) {
target[key] = defaults[key];
}
});
return target;
}
public static sort<T>(data: T[], state: ISortingState): T[] {
// set defaults
DataUtil.mergeDefaultProperties(state, SortingStateDefaults);
// apply default settings for each sorting expression(if not set)
return state.strategy.sort(data, state.expressions);
const sorting = new IgxSorting();
return sorting.sort(data, state.expressions);
}
public static group<T>(data: T[], state: IGroupingState): IGroupByResult {
// set defaults
DataUtil.mergeDefaultProperties(state, SortingStateDefaults);
// apply default settings for each grouping expression(if not set)
return state.strategy.groupBy(data, state.expressions);
const sorting = new IgxSorting();
return sorting.groupBy(data, state.expressions);
}
public static restoreGroups(groupData: IGroupByResult, state: IGroupingState, groupsRecords: any[] = []): any[] {
DataUtil.mergeDefaultProperties(state, SortingStateDefaults);
if (state.expressions.length === 0) {
return groupData.data;
}
Expand Down Expand Up @@ -140,29 +106,11 @@ export class DataUtil {
return data.slice(index * recordsPerPage, (index + 1) * recordsPerPage);
}
public static filter<T>(data: T[], state: IFilteringState): T[] {
// set defaults
DataUtil.mergeDefaultProperties(state, filteringStateDefaults);
if (!state.strategy) {
return data;
}
return state.strategy.filter(data, state.expressionsTree);
}
public static process<T>(data: T[], state: IDataState): T[] {
if (!state) {
return data;
}
if (state.filtering) {
data = DataUtil.filter(data, state.filtering);
}
if (state.sorting) {
data = DataUtil.sort(data, state.sorting);
}
if (state.paging) {
data = DataUtil.page(data, state.paging);
}
return data;
}

public static getHierarchy(gRow: IGroupByRecord): Array<IGroupByKey> {
const hierarchy: Array<IGroupByKey> = [];
if (gRow !== undefined && gRow.expression) {
Expand Down
Loading

0 comments on commit 3504e9e

Please sign in to comment.