import { HoistModel, PlainObject, SizingMode, Some } from '@xh/hoist/core'; import type { GridApi, IRowNode, SortDirection } from '@xh/hoist/kit/ag-grid'; import { GridSorterLike } from '../grid/GridSorter'; /** * Configuration for an {@link AgGridModel} - the low-level model backing the Hoist `AgGrid` * component. This interface is only relevant when using `AgGrid` directly for advanced or * minimally-managed ag-Grid use cases. Most applications should use {@link GridConfig} and * the standard {@link GridModel} instead, which extends this with columns, store binding, * selection, filtering, and other managed features. * * @see AgGridModel * @see GridConfig */ export interface AgGridModelConfig { sizingMode?: SizingMode; /** True to highlight the currently hovered row. */ showHover?: boolean; /** True to render row borders. */ rowBorders?: boolean; /** True to render row borders. */ cellBorders?: boolean; /** True to render cell borders. */ stripeRows?: boolean; /** True to highlight the focused cell with a border. */ showCellFocus?: boolean; /** True to suppress display of the grid's header row. */ hideHeaders?: boolean; /** @internal */ xhImpl?: boolean; } /** * @see https://www.ag-grid.com/javascript-grid-column-definitions/#saving-and-restoring-column-state */ export interface AgGridColumnState { isPivot: boolean; /** State of each column in the grid. */ columns: any[]; } export interface AgGridColumnSortState { colId: string; sort?: SortDirection; sortIndex: number; } export interface AgGridMiscState { /** Identifier of the currently open tool panel in the side bar*/ panelId: string; } export interface AgGridState { columnState?: AgGridColumnState; sortState?: AgGridColumnSortState[]; expandState?: any; filterState?: any[]; miscState?: AgGridMiscState; errors?: Record; } /** * Low-level model backing the {@link AgGrid} escape-hatch component - most applications should * use {@link GridModel} instead, which extends this class with columns, store binding, * selection, filtering, and other managed features. * * Provides reactive grid styling properties, access to the ag-Grid API, and utility methods * for getting/setting serializable grid state. * * @see AgGridModelConfig * @see GridModel */ export declare class AgGridModel extends HoistModel { static AUTO_GROUP_COL_ID: string; sizingMode: SizingMode; rowBorders: boolean; stripeRows: boolean; cellBorders: boolean; showHover: boolean; showCellFocus: boolean; hideHeaders: boolean; agApi: GridApi; private _prevSortBy; constructor({ sizingMode, showHover, rowBorders, cellBorders, stripeRows, showCellFocus, hideHeaders, xhImpl }?: AgGridModelConfig); /** True if the grid fully initialized and its state can be queried/mutated. */ get isReady(): boolean; /** * Retrieves the current state of the grid via ag-Grid APIs. This state is returned in a * serializable form and can be later restored via setState. */ getState(opts?: { excludeColumnState?: boolean; excludeSortState?: boolean; excludeExpandState?: boolean; excludeFilterState?: boolean; excludeMiscState?: boolean; }): AgGridState; /** * Sets the current state of the grid. This method should generally only be used with an object * returned by getState. * * Calls to this method should be made after the columns have been set in the grid. * * Some of the state may be data-dependent. Specifically the expandState and filterState. It is * recommended that applications wait until the data has been loaded in the grid before setting * the state if including those elements. This method can be called immediately after the data * has been loaded into the grid. */ setState(state: AgGridState): void; getMiscState(): AgGridMiscState; /** * Sets the grid state which doesn't fit into the other buckets. */ setMiscState(miscState: AgGridMiscState): void; /** * @returns Current filter state of the grid. * @see https://www.ag-grid.com/javascript-grid-filtering/#get-set-all-filter-models */ getFilterState(): PlainObject; /** * Sets the grid filter state. * Note that this state may be data-dependent, depending on the types of filter being used. */ setFilterState(filterState: any): void; /** * @returns current sort state of the grid. * @see https://www.ag-grid.com/javascript-grid-sorting/#sorting-api */ getSortState(): AgGridColumnSortState[]; /** * Sets the grid sort state. */ setSortState(sortState: AgGridColumnSortState[]): void; /** @returns current column state of the grid, including pivot mode */ getColumnState(): AgGridColumnState; /** Sets the columns state of the grid. */ setColumnState(colState: AgGridColumnState): void; /** * Sets the sort state on the grid's column state */ applySortBy(value: Some): void; /** * @returns the current row expansion state of the grid in a serializable form. * Returned object has keys for (stringified!) StoreRecordIds of all top-level * expanded rows and values of either `true` (if the row does not have any children, or * none are expanded) or a recursive object of the same shape (if children are expanded). */ getExpandState(): PlainObject; /** * Sets the grid row expansion state * @param expandState - grid expand state retrieved via getExpandState() */ setExpandState(expandState: PlainObject): void; /** @returns list of selected row node ids */ getSelectedRowNodeIds(): string[]; /** * Sets the selected row node ids. Any rows currently selected which are not in the list will be * deselected. * * @param ids - row node ids to mark as selected */ setSelectedRowNodeIds(ids: string[]): void; /** * @returns the id of the first row in the grid, after sorting and filtering, which * has data associated with it (i.e. not a group or other synthetic row). */ getFirstSelectableRowNodeId(): string; /** * @returns the first row in the grid, after sorting and filtering, which * has data associated with it (i.e. not a group or other synthetic row). */ getFirstSelectableRowNode(): IRowNode; /** * Sets the data used for rows which appear pinned to the top of the grid * @param data - the data to pin at the top of the grid */ setPinnedTopRowData(data: PlainObject[]): void; /** * @returns row data pinned to the top of the grid */ getPinnedTopRowData(): PlainObject[]; /** * Sets the data used for rows which appear pinned to the bottom of the grid * @param data - the data to pin at the bottom of the grid */ setPinnedBottomRowData(data: PlainObject[]): void; /** * @returns row data pinned to the bottom of the grid */ getPinnedBottomRowData(): PlainObject[]; handleGridReady({ api }: { api: any; }): void; handleGridUnmount(): void; private getPinnedRowData; private getPivotColumnId; private getGroupNodePath; private throwIfNotReady; }