@adaptabletools/adaptable
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
215 lines (214 loc) • 6.18 kB
TypeScript
import { BaseState } from './BaseState';
import { AdaptableObject } from './Common/AdaptableObject';
import { ColumnSort } from './Common/ColumnSort';
import { ColumnFilter, GridFilter } from '../types';
import { TableAggregationColumns, PivotAggregationColumns } from './Common/AggregationColumns';
import { RowSummary } from './Common/RowSummary';
import { NonEmptyArray } from '../Utilities/Extensions/ArrayExtensions';
/**
* Base Layout Type - Pivot or Table
*/
export type Layout = TableLayout | PivotLayout;
/**
* Array of Layouts - must contain at least one item
*/
export type LayoutArray = NonEmptyArray<Layout>;
/**
* Adaptable State Section for Layout Module, containing collection of Layouts and name of Current Layout
*/
export interface LayoutState extends BaseState {
/**
* Layout to be loaded when AdapTable starts (using `Name` property in Layout); if not provided the first Layout is used
*/
CurrentLayout?: string;
/**
* Collection of Layouts - can be Table or Pivot
*/
Layouts: LayoutArray;
}
/**
* Base object for both Table and Pivot Layouts
*/
export interface LayoutBase extends AdaptableObject {
/**
* Name of Layout as will appear in Layout toolbar and tool panel
*/
Name: string;
/**
* Map of Column Visibility
*/
ColumnVisibility?: ColumnBooleanFalseMap;
/**
* Set of widths for some (or all) Columns
*/
ColumnWidths?: ColumnNumberMap;
/**
* Defines which Row Groups are expanded / collapsed
*/
RowGroupValues?: RowGroupValues;
/**
* Set of custom header names for some (or all) Columns
*/
ColumnHeaders?: ColumnStringMap;
/**
* Hides the aggFunc in Column header: e.g. 'sum(Price)' becomes 'Price'
*/
SuppressAggFuncInHeader?: boolean;
/**
* Sorting to apply in the Layout
*/
ColumnSorts?: ColumnSort[];
/**
* Collection of Column Filters to apply in Layout
*/
ColumnFilters?: ColumnFilter[];
/**
* Grid Filter to apply in Layout
*/
GridFilter?: GridFilter;
/**
* Details of which Columns are pinned
*/
ColumnPinning?: ColumnDirectionMap;
/**
* Whether Columns should autosize when Layout first loads
*/
AutoSizeColumns?: boolean;
}
/**
* Defines a Table-based Layout
*/
export interface TableLayout extends LayoutBase {
/**
* Names of Columns to include in the Table Layout
*/
TableColumns: string[];
/**
* Row Summaries - Pinned Rows that display Aggregation Info for a whole column
*/
RowSummaries?: RowSummary[];
/**
* Columns showing aggregated values in Grouped Rows; a record of ColumnId and aggfunc (e.g. sum) or 'true' (to use default aggfunc)
*/
TableAggregationColumns?: TableAggregationColumns;
/**
* Columns which are row-grouped when the Layout is applied
*/
RowGroupedColumns?: string[];
/**
* Display Row Grouped Columns as 'single' or 'multi' column
*/
RowGroupDisplayType?: 'single' | 'multi';
/**
* Pivot Columns - must NOT be provided
*/
PivotColumns?: never;
/**
* Pivot Group Columns - must NOT be provided
*/
PivotGroupedColumns?: never;
/**
* Pivot Expansions - must NOT be provided
*/
PivotExpandLevel?: never;
/**
* Pivot Aggregation Columns - must NOT be provided
*/
PivotAggregationColumns?: never;
}
/**
* Defines a Pivot-based Layout
*/
export interface PivotLayout extends LayoutBase {
/**
* Mandatory list of Columns to pivot (provide empty array if just displaying Aggregations)
*/
PivotColumns: string[];
/**
* How deep to expand Pivot Columns (0 for none, 1 for 1st level only etc, -1 to expand all)
*/
PivotExpandLevel?: number;
/**
* Columns showing aggregated values in Group Rows; 1st value in record is Column name, 2nd is either aggfunc (e.g. sum, avg etc.) or 'true' (to use default aggfunc)
*/
PivotAggregationColumns?: PivotAggregationColumns;
/**
* Columns which are row-grouped when the Layout is applied
*/
PivotGroupedColumns?: string[];
/**
* Table Columns - must NOT be provided
*/
TableColumns?: never;
/**
* Table Aggregation Columns - must NOT be provided
*/
TableAggregationColumns?: never;
/**
* Row Grouped Columns Columns - must NOT be provided
*/
RowGroupedColumns?: never;
}
/**
* Manages how (and which) Row Group values are stored
*/
export type RowGroupValues = {
RowGroupDefaultBehavior: 'always-expanded' | 'always-collapsed';
} | RowGroupValuesWithExceptionKeys;
/**
* Defines which Row Group Values are expanded or collapsed
*/
export type RowGroupValuesWithExceptionKeys = {
RowGroupDefaultBehavior: 'expanded' | 'collapsed';
ExceptionGroupKeys?: any[][];
};
/**
* Defines a map of Columns with a String value
*/
export type ColumnStringMap = {
[columnId: string]: string;
};
/**
* Defines a map of Columns with a Number value
*/
export type ColumnNumberMap = {
[columnId: string]: number;
};
/**
* Defines a map of Columns with a Boolean value
*/
export type ColumnBooleanFalseMap = {
[columnId: string]: false;
};
/**
* Defines a map of Columns with a Left / Right direction value
*/
export type ColumnDirectionMap = {
[columnId: string]: 'left' | 'right';
};
/**
* The OLD Layout - kept temporarily so we can check what we previously had
*/
export interface LayoutOld extends AdaptableObject {
Name: string;
Columns: string[];
ColumnWidthMap?: {
[columnId: string]: number;
};
ColumnSorts?: ColumnSort[];
ColumnFilters?: ColumnFilter[];
GridFilter?: GridFilter;
RowGroupedColumns?: string[];
ExpandedRowGroupValues?: any[];
AggregationColumns?: Record<string, string | true | any>;
EnablePivot?: boolean;
PivotColumns?: string[];
PinnedColumnsMap?: {
[columnId: string]: 'left' | 'right';
};
ColumnHeadersMap?: {
[columnId: string]: string;
};
SuppressAggFuncInHeader?: boolean;
RowSummaries?: RowSummary[];
}