@adaptabletools/adaptable
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
616 lines (615 loc) • 22.4 kB
TypeScript
import { SelectedCellInfo } from '../AdaptableState/Selection/SelectedCellInfo';
import { SelectedRowInfo } from '../AdaptableState/Selection/SelectedRowInfo';
import { ColumnSort } from '../AdaptableState/Common/ColumnSort';
import { CellUpdateRequest, GridCell } from '../AdaptableState/Selection/GridCell';
import { DataUpdateConfig } from '../AdaptableState/Common/DataUpdateConfig';
import { CellDataChangedInfo } from '../AdaptableState/Common/CellDataChangedInfo';
import { CellHighlightInfo } from '../AdaptableState/Common/CellHighlightInfo';
import { RowHighlightInfo } from '../AdaptableState/Common/RowHighlightInfo';
import { CellSummmaryInfo } from '../AdaptableState/Common/CellSummary';
import { ColDef, ColGroupDef, Column, ColumnState, IRowNode, RowModelType } from 'ag-grid-enterprise';
import { GridCellRange } from '../AdaptableState/Selection/GridCellRange';
import { RowsHighlightInfo } from '../AdaptableState/Common/RowsHighlightInfo';
import { TransposeConfig } from '../AdaptableState/Common/TransposeConfig';
import { AdaptableVariant } from '../AdaptableInterfaces/IAdaptable';
import { InternalState } from '../AdaptableState/InternalState';
/**
* Provides access to important properties and functionalities of AdapTable e.g. sorting, selected cells etc.
*/
export interface GridApi {
/**
* Returns current AdapTable Variant: vanilla, angular, react, vue
*/
getVariant(): AdaptableVariant;
/**
* Returns the Internal section from AdapTable State
*/
getInternalState(): InternalState;
/**
* Retrieves all data from the grid
*/
getGridData(): any[];
/**
* Retrieves filtered data from the grid
*/
getFilteredData(): any[];
/**
* Retrieves visible data from the grid (filtered and sorted)
*/
getVisibleData(): any[];
/**
* Loads data into grid and fire a `RowChanged.trigger='Load'` event
* @param data data to load
*/
loadGridData(data: any): void;
/**
* Updates AdapTable (and AG Grid) with rows that have changed
* @param dataRows rows which have been updated - send whole row and AdapTable take cares of the rest
* @param config batch option and callback function to run post update
*/
updateGridData(dataRows: any[], config?: DataUpdateConfig): Promise<IRowNode[]>;
/**
* Adds or Updates AdapTable (and AG Grid) with new and changed rows
* @param dataRows rows to add or update
* @param config batch option and callback function to run post change
*/
addOrUpdateGridData(dataRows: any[], config?: DataUpdateConfig): Promise<{
addedRows: IRowNode[];
updatedRows: IRowNode[];
}>;
/**
* Adds rows to AdapTable (and AG Grid)
* @param dataRows rows to add; ensure all 'mandatory' fields are included and Primary Key is unique
* @param config batch option and callback function to run post addition
*/
addGridData(dataRows: any[], config?: DataUpdateConfig): Promise<IRowNode[]>;
/**
* Deletes rows from AdapTable (and AG Grid)
* @param dataRows rows which should be deleted
* @param config batch option and callback function to run post deletion
*/
deleteGridData(dataRows: any[], config?: DataUpdateConfig): Promise<IRowNode[]>;
/**
* Updates cell in AdapTable (first performs Cell & Server Validation)
* @param cellUpdateRequest (contains columnId, newValue and primaryKeyValue
*
*/
setCellValue(cellUpdateRequest: CellUpdateRequest): void;
/**
* Updates multiple cells
*/
setCellValues(cellUpdateRequests: CellUpdateRequest[]): void;
/**
* Reverses a data change (if triggered by cell edit)
* @param cellDataChangedInfo data change to undo
*/
undoCellEdit(cellDataChangedInfo: CellDataChangedInfo): boolean;
/**
* Returns summary info on Selected Cells
*/
getCellSummaryInfo(): CellSummmaryInfo;
/**
* Returns all current Selected Cells in AdapTable
*/
getSelectedCellInfo(): SelectedCellInfo;
/**
* Returns all current Selected Rows in AdapTable
*/
getSelectedRowInfo(): SelectedRowInfo;
/**
* Returns Column Sort information in AdapTable
*/
getColumnSorts(): ColumnSort[];
/**
* Retrieves ColumnSort for a given Column
* @param columnId Id of Column to retrieve ColumnSort
*/
getColumnSortForColumn(columnId: string): ColumnSort | undefined;
/**
* Applies current Filtering in AdapTable
*/
applyFiltering(): void;
/**
* Removes all current Filters in AdapTable
*/
clearFiltering(): void;
/**
* Sorts AdapTable using given Column Sorts
* @param columnSorts Column Sorts to use
*/
setAdaptableSorting(columnSorts: ColumnSort[]): void;
/**
* Removes Column Sorts in AdapTable
*/
clearAdaptableSorting(): void;
/**
* Selects the AG Grid Row Node in AdapTable
* @param rowNode Node to Select
* @param clearSelection Whether to clear current selection in grid
*/
selectNode(rowNode: IRowNode, clearSelection: boolean): void;
/**
* Selects the AG Grid Row Nodes in AdapTable
* @param rowNodes Nodes to Select
* @param clearSelection Whether to clear current selection in grid
*/
selectNodes(rowNodes: IRowNode[], clearSelection: boolean): void;
/**
* Deselects the AG Grid Row Node in AdapTable
* @param rowNode Node to DeSelect
* @param clearSelection Whether to clear current selection in grid
*/
deSelectNode(rowNode: IRowNode, clearSelection: boolean): void;
/**
* Selects a Column in AG Grid
* @param columnId Id of Column to Select
*/
selectColumn(columnId: string): void;
/**
* Selects Columns in AG Grid
* @param columnIds Ids of Columns to Select
*/
selectColumns(columnIds: string[]): void;
/**
* AG Grid Row Nodes in AdapTable
* @param rowNodes Nodes to DeSelect
* @param clearSelection Whether to clear current selection in grid
*/
deSelectNodes(rowNodes: IRowNode[], clearSelection: boolean): void;
/**
* Selects Row with given Primary Key Value
* @param primaryKeyValue Primary Key Value of Row to select
* @param clearSelection Whether to clear current selection in grid
*/
selectRow(primaryKeyValue: any, clearSelection: boolean): void;
/**
* Selects Rows with given Primary Key Values
* @param primaryKeyValues Primary Key Values of Rows to select
* @param clearSelection Whether to clear current selection in grid
*/
selectRows(primaryKeyValues: any[], clearSelection: boolean): void;
/**
* Deselects Row with given Primary Key Value
* @param primaryKeyValue Primary Key Value of Row to deselect
* @param clearSelection Whether to clear current selection in grid
*/
deSelectRow(primaryKeyValue: any, clearSelection: boolean): void;
/**
* Deselects Row with given Primary Key Values
* @param primaryKeyValues Primary Key Values of Rows to deselect
* @param clearSelection Whether to clear current selection in grid
*/
deSelectRows(primaryKeyValues: any[], clearSelection: boolean): void;
/**
* Selects a group of cells in a given range - provide either primary keys or row indexes
* @param gridCellRange Range to select
* @param clearSelection Whether to clear current selection in grid
*/
selectCellRange(gridCellRange: GridCellRange, clearSelection?: boolean): void;
/**
* Selects a group of cells in a given range using a query
*
* @param query query to use to select cells
* @param gridCellRange optional range to filter results
* @param clearSelection whether to clear current selection in grid
*/
selectCellRangeByQuery(query: string, gridCellRange?: GridCellRange, clearSelection?: boolean): void;
/**
* Retrieves the first Row Node in AdapTable
*/
getFirstRowNode(): IRowNode | undefined;
/**
* Retrieves the first Displayed Row Node in AdapTable
*/
getFirstDisplayedRowNode(): IRowNode | undefined;
/**
* Retrieves all filtered Row Nodes currently in the Grid (i.e. after applying the current filter)
* @param config - configuration
*/
getVisibleRowNodes(config?: {
includeGroupRows?: boolean;
filterFn?(rowNode: IRowNode): boolean;
}): IRowNode[];
/**
* Retrieves all Row Nodes currently in the Grid (by default excluding the group rows)
* @param config - configuration
*/
getAllRowNodes(config?: {
includeGroupRows?: boolean;
filterFn?(rowNode: IRowNode): boolean;
}): IRowNode[];
/**
* Retrieves all Grouped Row Nodes currently in the Grid
* @param config - configuration
*/
getGroupRowNodes(config?: {
filterFn?(rowNode: IRowNode): boolean;
}): IRowNode[];
/**
* Retrieves Row Nodes that contain given Primary Keys
* @param primaryKeyValues Primary Kev Values to look up
*/
getRowNodesForPrimaryKeys(primaryKeyValues: any[]): IRowNode[];
/**
* Retrieves Row Node that contains given Primary Key
* @param primaryKeyValue Primary Key Value to look up
*/
getRowNodeForPrimaryKey(primaryKeyValue: any): IRowNode;
/**
* Retrieves the displayed RowNode at the given index
* @param rowIndex row index
*/
getRowNodeForIndex(rowIndex: number): IRowNode | undefined;
/**
* Returns the Primary Kev Value for a given Row Node
* @param rowNode rowNode to look up
*/
getPrimaryKeyValueForRowNode(rowNode: IRowNode): any;
/**
* Returns the Primary Kev Values for a given Row Node collection
* @param rowNode rowNodes to look up
*/
getPrimaryKeyValuesForRowNodes(rowNodes: IRowNode[]): any[];
/**
* Retrieves Cell in given Row and Column
* @param rowNode Row to use
* @param columnId ColumnId to lookup
*/
getGridCellFromRowNode(rowNode: IRowNode, columnId: string): GridCell | undefined;
/**
* Retrieves Display Value for a given cell
* @param primaryKeyValue (unique) value in Primary Key Column
* @param columnId name of Column which contains the cell
*/
getCellDisplayValue(primaryKeyValue: any, columnId: string): any | undefined;
/**
* Retrieves Raw Value for a given cell
* @param primaryKeyValue (unique) value in Primary Key Column
* @param columnId name of Column which contains the cell
*/
getCellRawValue(primaryKeyValue: any, columnId: string): any | undefined;
/**
* Retrieves Normalised Value for a given cell
* @param primaryKeyValue (unique) value in Primary Key Column
* @param columnId name of Column which contains the cell
*/
getCellNormalisedValue(primaryKeyValue: any, columnId: string): any | undefined;
/**
* Retrieves Raw Value for Cell in given Row and Column
* @param rowNode Row to use
* @param columnId ColumnId to lookup
*/
getRawValueFromRowNode(rowNode: IRowNode, columnId: string): any | undefined;
/**
* Returns all the Grid Cells in a Column that have the given Raw Value
* @param columnId ColumnId to lookup
* @param rawValue Raw Value to use
*/
getGridCellsForRawValue(columnId: string, rawValue: any): GridCell[] | undefined;
/**
* Gets the count of the cells in a Column that have the given Raw Value
* @param columnId ColumnId to lookup
* @param rawValue Raw Value to use
*/
getCellRawValueCount(columnId: string, rawValue: any): number;
/**
* Returns all the Grid Cells in a Column that have the given Display Value
* @param columnId ColumnId to lookup
* @param displayValue Display Value to use
*/
getGridCellsForDisplayValue(columnId: string, displayValue: any): GridCell[] | undefined;
/**
* Retrieves Formatted Value for a given Raw Value in given Column
* @param columnId ColumnId to lookup
* @param rawValue Raw Value
* @param rowNode Node containig the Column
*/
getDisplayValueFromRawValue(rowNode: IRowNode, columnId: string, rawValue: any): string | undefined;
/**
* Retrieves Display Value for Cell in given Row and Column
* @param rowNode Row to use
* @param columnId ColumnId to lookup
*/
getDisplayValueFromRowNode(rowNode: IRowNode, columnId: string): any | undefined;
/**
* Retrieves Normalised Value for Cell in given Row and Column
* @param rowNode Row to use
* @param columnId ColumnId to lookup
*/
getNormalisedValueFromRowNode(rowNode: IRowNode, columnId: string): any | undefined;
/**
* Sets the grid to Row Group
* @param columnIds ColumnIds to row group
*/
setRowGroupColumns(columnIds: string[]): void;
/**
* Clears Row Grouping in the Grid
*/
clearRowGroupColumns(): void;
/**
* Expands all closed groups in Row Grouping
*/
expandAllRowGroups(): void;
/**
* Collapse all open groups in Row Grouping
*/
collapseAllRowGroups(): void;
/**
* Expands Row Groups that contain given keys
* @param columnValues values to open Row Groups for
*/
expandRowGroupsForValues(columnValues: any[]): void;
/**
* Whether AdapTable instance can be pivoted
*/
isGridPivotable(): boolean;
/**
* Whether AdapTable instance can be Row Grouped
*/
isGridGroupable(): boolean;
/**
* Whether AdapTable instance offers row selection
*/
isGridRowSelectable(): boolean;
/**
* Whether a Row is selected
* @param primaryKeyValue pkVaue of Row to check
*/
isGridRowSelected(primaryKeyValue: any): boolean;
/**
* Whether AdapTable instance offers cell range selection
*/
isGridRangeSelectable(): boolean;
/**
* Whether Grid is currently showing Row Groups
*/
isGridRowGrouped(): boolean;
/**
* Whether Grid is currently in Pivot Mode
*/
isGridInPivotMode(): boolean;
/**
* Whether Grid displays a Tree Data (structured hierarchical data)
*/
isTreeDataGrid(): boolean;
/**
* Whether Grid is a Master Detail Grid
*/
isMasterDetailGrid(): boolean;
/**
* Whether given Row Node is a Row Group
* @param rowNode Node to check
*/
isGroupRowNode(rowNode: IRowNode): boolean;
/**
* Whether given Row Node is visible
* @param rowNode Node to check
*/
isVisibleRowNode(rowNode: IRowNode): boolean;
/**
* Whether given Row Node is in a Summary Row
* @param rowNode Node to check
*/
isSummaryNode(rowNode: IRowNode): boolean;
/**
* Whether Quick Filter is available in the Grid
*/
isQuickFilterAvailable(): boolean;
/**
* Redraws AdapTable (expensive operation so use sparingly)
*/
redrawGrid(): void;
/**
* Grid will jump to Row containing given Primary Kev Value
* @param primaryKeyValue value in Primary Key Column
*/
jumpToRow(primaryKeyValue: any): void;
/**
* Grid will jump to Column that has given ColumnId
* @param columnId Id of Column to jump to
*/
jumpToColumn(columnId: string): void;
/**
* Grid will jump to cell in a given Row and Column
* @param primaryKeyValue value in Primary Key Column
* @param columnId Id of Column
* @param rowNode AG Grid RowNode
*/
jumpToCell(primaryKeyValue: any, columnId: string, rowNode?: IRowNode): void;
/**
* Highlights a Cell in AdapTable
* @param cellHighlightInfo cell to highlight
*/
highlightCell(cellHighlightInfo: CellHighlightInfo): void;
/**
* Unhighlights a Cell in AdapTable
* @param cellHighlightInfo cell to unhighlight
*/
unHighlightCell(primaryKeyValue: CellHighlightInfo['primaryKeyValue'], columnId: CellHighlightInfo['columnId']): void;
/**
* Unhighlights all highlighted Cells in AdapTable
* @param cellHighlightInfo cell to highlight
*/
unHighlightAllCells(): void;
/**
* Highlight a row using an adaptable style
* @param rowHighlightInfo highlight instructions
*/
highlightRow(rowHighlightInfo: RowHighlightInfo): void;
/**
* Highlight rows using an adaptable style
* @param rowHighlightInfo highlight instructions
*/
highlightRows(rowsHighlightInfo: RowsHighlightInfo): void;
/**
* Remove highlight from Row
* @param primaryKeyValue value in Primary Key Column
*/
unHighlightRow(primaryKeyValue: RowHighlightInfo['primaryKeyValue']): void;
/**
* Remove highlight from given Rows
* @param primaryKeyValues values in Primary Key Column
*/
unHighlightRows(primaryKeyValues: RowsHighlightInfo['primaryKeyValues']): void;
/**
* Remove all highlighted rows
*/
unHighlightAllRows(): void;
/**
* Refresh Column Values in AdapTable
* @param columnId - the ID of the Column to refresh
*/
refreshColumn(columnId: string): void;
/**
* Refresh Columns Values in AdapTable
* @param columnIds - the IDs of the Columns to refresh
*/
refreshColumns(columnIds: string[]): void;
/**
* Refresh a Cell Value in AdapTable
* @param rowNode AG Grid RowNode which contains cell to refresh
* @param columnId ColumnId which contains cell to refresh
*/
refreshCell(rowNode: IRowNode, columnId: string, suppressFlash?: boolean): void;
/**
* Refresh Cell Values in AdapTable
* @param rowNode agGrid RowNode which contains cells to refresh
* @param columnIds ColumnIds which contain cells to refresh
*/
refreshCells(rowNode: IRowNode, columnIds: string[], suppressFlash?: boolean): void;
/**
* Refreshes all Cells in the Grid
* @param forceUpdate forces AG Grid change detection
*/
refreshAllCells(forceUpdate?: boolean): void;
/**
* Refreshes a single Grid Cell
* @param gridCell GridCell to refresh
*/
refreshGridCell(gridCell: GridCell): void;
/**
* Refreshes a set of Grid Cells
* @param gridCells GridCells to refresh
*/
refreshGridCells(gridCells: GridCell[]): void;
/**
* Forces a re-render of Row with given Primary Key value
* @param primaryKey row primary key
*/
refreshRowByPrimaryKey(primaryKey: any): void;
/**
* Forces a re-render of the given row
* @param rowNode AG Grid Row
*/
refreshRowNode(rowNode: IRowNode): void;
/**
* Forces a re-render of the given rows
* @param rowNodes AG Grid rows
*/
refreshRowNodes(rowNodes: IRowNode[]): void;
/**
* Forces a re-render of all Group Rows (including aggregations)
*/
refreshGroupRowNodes(): void;
/**
* Returns number of rows in Data Source
*/
getRowCount(): number;
/**
* Returns number of rows in Data Source
*/
getVisibleRowCount(): number;
/**
* Returns number of columns in Data Source
*/
getColumnCount(): number;
/**
* Returns number of visible columns in Data Source
*/
getVisibleColumnCount(): number;
/**
* Checks if given Grid Cell is editable
* @param gridCell Cell to check
*/
isCellEditable(gridCell: GridCell): boolean;
/**
* Checks if given Grid Cell has been edited (uses Data Change History)
* @param gridCell Cell to check
*/
isCellEdited(gridCell: GridCell): boolean;
/**
* Checks if all of given Grid Cells are editable
* @param gridCells cells to check
*/
isEveryCellEditable(gridCells: GridCell[]): boolean;
/**
* Select the whole Grid
*/
selectAll(): void;
/**
* Deselects all selected rows, cells and ranges
*/
deselectAll(): void;
/**
* Returns the Grid Container in which the AdapTable Instance is present
*/
getGridContainerElement(): HTMLElement | null;
/**
* Opens Settings Panel with Grid Info section selected and visible
*/
openGridInfoSettingsPanel(): void;
/**
* Returns AG Grid Row Model Type
*/
getAgGridRowModelType(): RowModelType;
/**
* Opens a window with a transposed view of Grid
*/
showTransposedView(transposeConfig?: TransposeConfig): void;
/**
* Return all AG Grid columns
*/
getAllAgGridColumns(): Column<any>[];
/**
* Updates Ag Grid Column State for a given Column; use to update STATEFUL AG Grid Column props
* @param columnState - the AG Grid ColumnState to set
*/
updateAgGridColumnState(columnState: ColumnState): void;
/**
* Updates Ag Grid Column State for given Columns; use to update STATEFUL AG Grid Column props
* @param columnStates - the AG Grid ColumnState to set
*/
updateAgGridColumnStates(columnStates: ColumnState[]): void;
/**
* Sets the Column Definitions for the Grid
*/
setAgGridColumnDefinitions(columnDefinitions: (ColDef | ColGroupDef)[]): void;
/**
* Updates Column Definition for given Column; use to update NON-STATEFUL AG Grid Column props (which are merged with existing Column Def)
* @param columnId - the ColumnId to update
* @param columnDefinition - the new Column Definition
*/
updateAgGridColumnDefinition(columnDefinition: ColDefWithId): void;
/**
* Updates Column Definition for given Columns; use to update NON-STATEFUL AG Grid Column props (which are merged with existing Column Def)
* @param columnId - the ColumnId to update
* @param columnDefinition - the new Column Definition
*/
updateAgGridColumnDefinitions(columnDefinitions: ColDefWithId[]): void;
/**
* Removes the Column Definition for a given Column.
* @param columnId - the ColumnId to remove
*/
removeAgGridColumnDefinition(columnId: string): void;
/**
* Adds a Column Definition to the Grid
* @param columnDefinition - the new Column Definition
*/
addAgGridColumnDefinition(columnDefinition: ColDefWithId): void;
}
/**
* AG Grid Column Definition with a mandatory `colId` property
*/
export type ColDefWithId = Omit<ColDef, 'colId'> & {
colId: string;
};