@adaptabletools/adaptable
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
36 lines (35 loc) • 1.57 kB
TypeScript
import { DeepMap } from './deepMap';
export type GroupKeyType<T extends any = any> = T;
export type GroupBy<DataType, KeyType> = {
field: keyof DataType;
toKey?: (value: any, data: DataType) => GroupKeyType<KeyType>;
};
export type GroupParams<DataType, KeyType> = {
groupBy: GroupBy<DataType, KeyType>[];
defaultToKey?: (value: any, item: DataType) => GroupKeyType<KeyType>;
reducers?: Record<string, DataSourceAggregationReducer<DataType, any>>;
};
export type DataSourceAggregationReducer<T, AggregationResultType> = {
name?: string;
field?: keyof T;
initialValue?: AggregationResultType;
getter?: (data: T) => any;
reducer: string | ((accumulator: any, value: any, data: T) => AggregationResultType | any);
done?: (accumulatedValue: AggregationResultType | any, array: T[]) => AggregationResultType;
};
export type DataGroupResult<DataType, KeyType extends any> = {
deepMap: DeepMap<GroupKeyType<KeyType>, DeepMapGroupValueType<DataType, KeyType>>;
groupParams: GroupParams<DataType, KeyType>;
initialData: DataType[];
reducerResults?: Record<string, any>;
};
export type DeepMapGroupValueType<DataType, KeyType> = {
items: DataType[];
commonData?: Partial<DataType>;
reducerResults: Record<string, any>;
};
export type AggregationReducerResult<AggregationResultType extends any = any> = {
value: AggregationResultType;
id: string;
};
export declare function group<DataType, KeyType = any>(groupParams: GroupParams<DataType, KeyType>, data: DataType[]): DataGroupResult<DataType, KeyType>;