UNPKG

@adaptabletools/adaptable

Version:

Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements

129 lines (128 loc) 4.87 kB
import { AdaptableColumnMenuItemName, AdaptableMenuItem, AgGridMenuItem, ColumnMenuContext, MenuSeparator } from '../AdaptableState/Common/Menu'; import { AdaptableIcon } from '../types'; import { MenuItemFrameworkComponent } from '../agGrid/AdaptableFrameworkComponent'; /** * Options for managing menus in AdapTable – provided using 2 collections */ export interface ColumnMenuOptions<TData = any> { /** * Customises Column Menu (default column menu items are available in the provided context) */ customColumnMenu?: (menuContext: CustomColumnMenuContext<TData>) => CustomColumnMenuItem[]; } /** * Context info provided when building Custom Column Menus */ export interface CustomColumnMenuContext<TData = any> extends ColumnMenuContext<TData> { /** * Flat list of all available AdapTable Menu Items */ defaultAdaptableMenuItems: AdaptableSystemColumnMenuItem<AdaptableColumnMenuItemName>[]; /** * Flat list of all available AG Grid Menu Items */ defaultAgGridMenuItems: AgGridMenuItem<AgGridColumnMenuItemType>[]; /** * Default structure of Adaptable Menu Items */ defaultAdaptableMenuStructure: (AdaptableSystemColumnMenuItem<AdaptableColumnMenuItemName> | MenuSeparator)[]; /** * Default structure of AG Grid Menu Items */ defaultAgGridMenuStructure: (AgGridMenuItem<AgGridColumnMenuItemType> | { menuType: 'Group'; label: string; subMenuItems: AgGridMenuItem<AgGridColumnMenuItemType>[]; disabled?: boolean; icon?: AdaptableIcon; })[]; } /** * Custom Column Menu Item */ export type CustomColumnMenuItem = AgGridMenuItem<AgGridColumnMenuItemType> | AdaptableSystemColumnMenuItem<AdaptableColumnMenuItemName> | UserColumnMenuItem | MenuSeparator | CustomGroupColumnMenuItem; /** * Defines a Grouped Menu Item in the Column Menu */ export type CustomGroupColumnMenuItem = { menuType: 'Group'; label: string; subMenuItems: CustomColumnMenuItem[]; disabled?: boolean; icon?: AdaptableIcon; }; /** * System Menu Item that is provided by AdapTable */ export interface AdaptableSystemColumnMenuItem<MENU_TYPE_NAME extends AdaptableColumnMenuItemName> extends AdaptableMenuItem<MENU_TYPE_NAME> { /** * Type of Menu - always 'Adaptable' */ menuType: 'Adaptable'; } /** * Column Menu Item that is provided by User */ export interface UserColumnMenuItem { /** * Type of Menu - always 'User' */ menuType: 'User'; /** * Text to appear in the Menu Item */ label: string; /** * Function invoked when the Menu Item is clicked */ onClick?: (menuContext: ColumnMenuContext) => void; /** * Whether menu item is disabled */ disabled?: boolean; /** * Whether menu item is hidden */ hidden?: boolean; /** * Optional icon to display */ icon?: AdaptableIcon; /** * Array of Menu Items, enabling limitless levels of menus */ subMenuItems?: CustomColumnMenuItem[]; /** * Optional Framework Component (React, Angular or Vue) used to render the * content of this menu item. * * When supplied, AG Grid renders the component inside the menu row using * its own framework adapter. The component receives AG Grid's * `CustomMenuItemProps`, with the AdapTable-specific extras * (`adaptableApi`, `menuContext`, plus anything passed via * `menuItemParams`) available as `props.menuItemParams`. * * Supported in the React, Vue and Angular variants of AdapTable. * * For Vue, supply a factory that returns the Vue Component (NOT a render * call), e.g. `({ adaptableApi }) => MyMenuItem`. AG Grid Vue then * instantiates the component using its own framework adapter and passes * `name`, `icon`, `menuItemParams`, ... as props. * * For Angular, supply `{ type: MyMenuItemComponent }` where the component * implements `IMenuItemAngularComp` (with `agInit(params)` to receive * `params.menuItemParams.adaptableApi` and `params.menuItemParams.menuContext`). * The `onSetup` callback on `AngularFrameworkComponent` is NOT honoured * for menu items because AG Grid owns the component lifecycle. */ frameworkComponent?: MenuItemFrameworkComponent<ColumnMenuContext>; /** * Extra parameters passed through to the Framework Component (alongside * `adaptableApi` and `menuContext`). */ menuItemParams?: Record<string, unknown>; } /** * Defines AG Grid Column Menu Items */ export type AgGridColumnMenuItemType = 'sortAscending' | 'sortDescending' | 'sortUnSort' | 'columnFilter' | 'columnChooser' | 'pinSubMenu' | 'valueAggSubMenu' | 'autoSizeThis' | 'autoSizeAll' | 'rowGroup' | 'rowUnGroup' | 'resetColumns' | 'expandAll' | 'contractAll' | 'separator';