GridApi is the primary interface for interacting with the AG Grid programmatically. It provides methods to control the grid’s behavior, manage data, and respond to user interactions.
Overview
Access the Grid API via theonGridReady event:
Core Methods
Grid Lifecycle
Returns the
gridId for the current grid as specified via the gridOptions property gridId or the auto assigned grid id if none was provided.Will destroy the grid and release resources. If you are using a framework you do not need to call this, as the grid links in with the framework lifecycle. However if you are using Web Components or native JavaScript, you do need to call this, to avoid a memory leak in your application.
Returns
true if the grid has been destroyed.Grid Options
Returns the grid option value for a provided key.
Updates a single gridOption to the new value provided. Cannot be used on
Initial properties. If updating multiple options, it is recommended to instead use api.updateGridOptions() which batches update logic.Updates the provided subset of gridOptions with the provided values. Cannot be used on
Initial properties.Row Selection API
Row Selection Methods
Row Selection Methods
setNodesSelected
(params: { nodes: IRowNode<TData>[]; newValue: boolean; source?: SelectionEventSourceType }) => void
Set all of the provided nodes selection state to the provided value.Module:
RowSelectionModuleSelect all rows. By default this ignores filtering, expansion and pagination settings. Pass the appropriate select all mode as an argument in order to select only rows that satisfy the filter, or those rows on the current page.Module:
RowSelectionModuleParameters:mode: SelectAll mode to use. SeeSelectAllModesource: Source property that will appear in theselectionChangedevent, defaults to'apiSelectAll'
Clear all row selections. By default this ignores filtering, expansion and pagination settings.Module:
RowSelectionModuleReturns an unsorted list of selected nodes. Getting the underlying node (rather than the data) is useful when working with tree / aggregated data, as the node can be traversed.Module:
RowSelectionModuleReturns an unsorted list of selected rows (i.e. row data that you provided).Module:
RowSelectionModuleRow API
Remove row(s) from the DOM and recreate them again from scratch.Module:
RowApiModulesetRowNodeExpanded
(rowNode: IRowNode<TData>, expanded: boolean, expandParents?: boolean, forceSync?: boolean) => void
Expand or collapse a specific row node, optionally expanding/collapsing all of its parent nodes. By default rows are expanded asynchronously for best performance. Set
forceSync: true if you need to interact with the expanded row immediately after this function.Module: RowApiModuleReturns the row node with the given ID. The row node ID is the one you provide from the callback
getRowId(params), otherwise the ID is a number (cast as string) auto-generated by the grid when the row data is set.Module: RowApiModuleforEachNode
(callback: (rowNode: IRowNode<TData>, index: number) => void, includeFooterNodes?: boolean) => void
Iterates through each node (row) in the grid and calls the callback for each node. This works similar to the
forEach method on a JavaScript array. This is called for every node, ignoring any filtering or sorting applied within the grid.Module: RowApiModuleReturns the total number of displayed rows.Module:
RowApiModuleColumn API
Returns all the columns, regardless of visible or not.Module:
ColumnApiModuleReturns the column with the given
colKey, which can either be the colId (a string) or the colDef (an object).Module: ColumnApiModuleSets the visibility of columns. Key can be the column ID or
Column object.Module: ColumnApiModuleSet a column’s pinned / unpinned state. Key can be the column ID, field,
ColDef object or Column object.Module: ColumnApiModuleFilter API
Sets the state of all the column filters. Provide it with what you get from
getFilterModel() to restore filter state.Module: TextFilterModule / NumberFilterModule / DateFilterModule / SetFilterModule / MultiFilterModule / CustomFilterModuleGets the current state of all the column filters. Used for saving filter state.Module:
TextFilterModule / NumberFilterModule / DateFilterModule / SetFilterModule / MultiFilterModule / CustomFilterModuleReturns
true if any filter is set. This includes quick filter, column filter, external filter or advanced filter.Module: TextFilterModule / NumberFilterModule / DateFilterModule / SetFilterModule / MultiFilterModule / CustomFilterModule / QuickFilterModule / ExternalFilterModule / AdvancedFilterModuleEvent Handling
addEventListener
<TEventType extends AgPublicEventType>(eventType: TEventType, listener: AgEventListener<TData, any, TEventType>) => void
Add an event listener for the specified
eventType. Listener will receive the event as a single parameter. Listeners will be automatically removed when the grid is destroyed.Module: EventApiModuleremoveEventListener
<TEventType extends AgPublicEventType>(eventType: TEventType, listener: AgEventListener<TData, any, TEventType>) => void
Remove an event listener.Module:
EventApiModuleEditing API
Start editing the provided cell. If another cell is editing, the editing will be stopped in that other cell.Module:
TextEditorModule / LargeTextEditorModule / NumberEditorModule / DateEditorModule / CheckboxEditorModule / CustomEditorModule / SelectEditorModule / RichSelectModuleIf a cell is editing, it stops the editing. Pass
true if you want to cancel the editing (i.e. don’t accept changes).Module: TextEditorModule / LargeTextEditorModule / NumberEditorModule / DateEditorModule / CheckboxEditorModule / CustomEditorModule / SelectEditorModule / RichSelectModuleRelated APIs
GridOptions
Configure grid behavior and appearance
Column API
Deprecated column-specific methods (now part of GridApi)
Grid Events
Listen to grid-level events