@adaptabletools/adaptable
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
275 lines (274 loc) • 7.73 kB
TypeScript
import { Column } from 'ag-grid-enterprise';
import { AdaptableColumnGroup, AdaptableColumnType, BaseContext, Layout } from '../types';
import { TypeHint } from '../AdaptableState/Common/Types';
/**
* Options related to managing Columns in Adaptable.
*/
export interface ColumnOptions {
/**
* Provide an alternative Friendly Name for a Column
* @defaultValue undefined
*/
columnFriendlyName?: (columnFriendlyNameContext: ColumnFriendlyNameContext) => string | undefined;
/**
* Provide a custom Header Name for a Table or Pivot Column
*/
columnHeader?: (context: ColumnHeaderContext) => string;
/**
* Optional list of Column Types - used for Scope and creating Special Columns
* @defaultValue Empty Array
*/
columnTypes?: TypeHint<string, AdaptableColumnType>[] | ((context: ColumnTypesContext) => TypeHint<string, AdaptableColumnType>[]);
/**
* Log warning to console if AdapTable cannot find a column
*
* @defaultValue true
* @gridInfoItem
* @noCodeItem
*/
showMissingColumnsWarning?: boolean;
/**
* Appends the name of the Column Group to a Column's Friendly Name
*
* @defaultValue false
* @gridInfoItem
* @noCodeItem
*/
addColumnGroupToColumnFriendlyName?: boolean;
}
/**
* Common properties for Column Header Context
*/
export interface BaseColumnHeaderContext extends BaseContext {
/**
* The default header name for the column
*/
defaultHeaderName: string;
/**
* The mame of the current Layout
*/
currentLayoutName: string;
/**
* The type (table/pivot) of the current Layout
*/
currentLayoutType: 'table' | 'pivot';
/**
* The current Layout
*/
currentLayout: Layout;
}
/**
* Context for Columns created automatically by AG Grid when grouping
*/
export interface AutoGroupColumnHeaderContext extends BaseColumnHeaderContext {
/**
* Auto-generated Group Column when GroupDisplayType is `single` column
*/
columnType: 'autoGroupColumn';
/**
* Technical ID of the Column
*/
columnId: string;
/**
* IDs of the Columns that are grouped
*/
groupedColumnIds: string[];
}
/**
* Context for Columns created when Row Grouping
*/
export interface RowGroupColumnHeaderContext extends BaseColumnHeaderContext {
/**
* A Row Grouped Column - see `TableLayout.RowGroupedColumns` or `PivotLayout.PivotGroupedColumns`
*/
columnType: 'rowGroupColumn';
/**
* Technical ID of the Column
*/
columnId: string;
/**
* ID of the grouped Column
*/
groupColumnId: string;
}
/**
* Context for standard Table Layout Columns
*/
export interface TableColumnHeaderContext extends BaseColumnHeaderContext {
/**
* Table Column - see `TableLayout.TableColumns`
*/
columnType: 'tableColumn';
/**
* Technical ID of the Column
*/
columnId: string;
/**
* Optional Aggregation function of the Column - see `TableLayout.TableAggregationColumns`
*/
aggregation?: string;
}
/**
* Context for Column Group headers
*/
export interface TableColumnGroupHeaderContext extends BaseColumnHeaderContext {
/**
* Column Group (used when Column Grouping)
*/
columnType: 'tableColumnGroup';
/**
* Technical ID of the Column Group - see `ColGroupDef.groupId`
*/
groupId: string;
/**
* IDs of the Column Group children - see `ColGroupDef.children`
*/
childrenColumnIds: string[];
/**
* State of the Column Group
*/
state: 'expanded' | 'collapsed';
}
/**
* Context for Pivot Column Groups
*/
export interface PivotColumnGroupHeaderContext extends BaseColumnHeaderContext {
/**
* Pivot Column Column - created by `PivotLayout.PivotColumns`
*/
columnType: 'pivotColumnGroup';
/**
* Technical ID of the generated Column Group
*/
groupId: string;
/**
* Pivot Keys for the current Column Group
*/
pivotKeys: string[];
/**
* State of the Column Group
*/
state: 'expanded' | 'collapsed';
}
/**
* Context for Pivot Result Columns
*/
export interface PivotResultColumnHeaderContext extends BaseColumnHeaderContext {
/**
* Pivot Result Column - intersecton of `PivotLayout.PivotAggregationColumns` and `PivotLayout.PivotColumns`
*/
columnType: 'pivotResultColumn';
/**
* Technical ID of the generated Column
*/
columnId: string;
/**
* Current Pivot Keys
*/
pivotKeys: string[];
/**
* ID of the Aggregated Column - see `PivotLayout.PivotAggregationColumns`
*/
aggregatedColumnId: string;
/**
* Aggregation function of the Column - see `PivotLayout.PivotAggregationColumns.AggregationColumnValue`
*/
aggregation: string;
}
/**
* Context for Pivot Grand Total Columns
*/
export interface PivotGrandTotalHeaderContext extends BaseColumnHeaderContext {
/**
* Pivot Grand Total - see `PivotLayout.PivotGrandTotal`
*/
columnType: 'pivotGrandTotal';
/**
* ID of the Aggregated Column - see `PivotLayout.PivotAggregationColumns`
*/
aggregatedColumnId: string;
/**
* Aggregation function of the Column - see `PivotLayout.PivotAggregationColumns.AggregationColumnValue`
*/
aggregation: string;
}
/**
* Context for Pivot Total Columns
*/
export interface PivotColumnTotalHeaderContext extends BaseColumnHeaderContext {
/**
* Pivot Column Total - see `PivotLayout.PivotColumnTotal`
*/
columnType: 'pivotColumnTotal';
/**
* Current Pivot Keys
*/
pivotKey: string;
/**
* ID of the Pivot Column - see `PivotLayout.PivotColumns`
*/
pivotColumnId: string;
/**
* Aggregation function of the Column - see `PivotLayout.PivotAggregationColumns.AggregationColumnValue`
*/
aggregation: string;
}
/**
* Context for Pivot Aggregation Totals
*/
export interface PivotAggregationTotalHeaderContext extends BaseColumnHeaderContext {
/**
* Pivot Aggregation Total Column - see `PivotLayout.PivotAggregationColumns.TotalColumn`
*/
columnType: 'pivotAggregationTotal';
/**
* ID of the Aggregated Column - see `PivotLayout.PivotAggregationColumns`
*/
aggregatedColumnId: string;
/**
* Aggregation function of the Column - see `PivotLayout.PivotAggregationColumns.AggregationColumnValue`
*/
aggregation: string;
/**
* ID of the Pivot Column - see `PivotLayout.PivotColumns`
*/
pivotColumnId: string;
/**
* Current Pivot Keys
*/
pivotKey: string;
}
/**
* Context provided to columnHeader function custom Headers to be provided for any type of AG Grid Column
*/
export type ColumnHeaderContext = TableColumnHeaderContext | TableColumnGroupHeaderContext | AutoGroupColumnHeaderContext | RowGroupColumnHeaderContext | PivotColumnGroupHeaderContext | PivotResultColumnHeaderContext | PivotGrandTotalHeaderContext | PivotColumnTotalHeaderContext | PivotAggregationTotalHeaderContext;
/**
* Context used when setting a Column Friendly Name
*/
export interface ColumnFriendlyNameContext extends BaseContext {
/**
* Id of the Column
*/
colId: string;
/**
* AG Grid Display Name
*/
displayName: string;
/**
* AG Grid ColDef for the Column
*/
agColumn: Column;
/**
* Column Group Information
*/
columnGroup: AdaptableColumnGroup;
}
/**
* Context used when retrieving Column Types
*/
export interface ColumnTypesContext extends BaseContext {
/**
* Current Column Types
*/
types: string[];
}