AG grid

AG Grid is designed for working with large tables. The component supports sorting, virtual scrolling, resizing, and reordering of columns. It is based on the library ag-grid-angular.

To maintain a consistent table style across projects, a theme @koobiq/ag-grid-angular-theme has been created. It includes ready-to-use styles that align with the design system. The theme supports the core features of AG Grid and simplifies table appearance customization.

Install the following packages:

npm install @koobiq/ag-grid-angular-theme@^34 ag-grid-community@^34 ag-grid-angular@^34

Import the theme into the main styles file styles.scss:

@use '@koobiq/ag-grid-angular-theme';

Apply the theme to <ag-grid-angular> in the template:

import { KbqAgGridThemeModule } from '@koobiq/ag-grid-angular-theme';
import { AgGridModule } from 'ag-grid-angular';

@Component({
    imports: [AgGridModule, KbqAgGridThemeModule],
    template: `<ag-grid-angular kbqAgGridTheme />`
})

The full documentation for using the theme is available in the GitHub repository.

To disable the focus styles for table cells, add the kbqAgGridThemeDisableCellFocusStyles attribute to <ag-grid-angular>:

<ag-grid-angular kbqAgGridTheme kbqAgGridThemeDisableCellFocusStyles />

The kbqAgGridRowActions directive adds an action panel that appears when hovering over a row.

The kbqAgGridRowGroup directive implements client-side row grouping. Attach it to ag-grid-angular, supply raw data via [kbqAgGridRowGroupRowData] instead of [rowData], and set the grouped columns via [(kbqAgGridRowGroupCols)].

Collapsed/expanded group state and row selection can each be persisted independently by setting kbqAgGridRowGroupCollapsedState and kbqAgGridRowGroupSelectionState to a unique key, connecting store providers via kbqAgGridRowGroupCollapsedStateStoreProvider and kbqAgGridRowGroupSelectionStateStoreProvider.

The kbqAgGridRowDetail directive expands a row to show a custom component below it. Pass the component via kbqAgGridRowDetailComponent and set getRowId. The component receives the row data and the collapse() method through the KBQ_AG_GRID_ROW_DETAIL_PARAMS token.

The behavior of expanded rows is configured with the following inputs:

InputDescription
kbqAgGridRowDetailSingleExpandKeeps only one row expanded
kbqAgGridRowDetailFilledFills the expanded row with a background
kbqAgGridRowDetailStickyKeeps the expanded part in place during horizontal scrolling

The directive methods are available via #rowDetail="kbqAgGridRowDetail":

MethodDescription
expand(id)Expands the row
collapse(id)Collapses the row
toggle(id)Expands or collapses the row
collapseAll()Collapses all rows

In the example, a click on a cell and Enter on a row call toggle(). The expanded part is not a cell, so clicking it does not collapse the row, and clicking the selection checkbox does not expand it.

The screen reader labels of the expand toggle are Russian by default. To switch the language, provide a labels provider:

providers: [kbqAgGridRowDetailLabelsProvider(KBQ_AG_GRID_ROW_DETAIL_LABELS_EN)];

The Actions panel component allows you to perform bulk actions on rows selected in the table. To prevent the panel from overlapping the last rows of the table, a padding-bottom is added to .ag-body-viewport when it opens.

The Content panel component shows a quick preview of the row selected in the table, shifting the table instead of covering it.

A long list can fit into a single line of a cell: Overflow items hides what does not fit the width and recalculates that whenever the column is resized. The hidden items can be expanded in the cell itself or shown as a full list in a Popover. To let the row height follow the content, enable autoHeight for the column.

The kbqAgGridCopyByCtrlC directive allows you to copy selected rows to the clipboard using the Ctrl+C keyboard shortcut.

The grid's own API can be used to export the currently displayed data (respecting active filters, sorting, and formatters). api.exportDataAsCsv() downloads a CSV file with no additional dependencies. Other formats can be built on top of the grid's cell values using third-party libraries — for example, XLSX via write-excel-file, and PDF via jspdf with jspdf-autotable.

The kbqAgGridStatusBar directive adds a customizable panel below the table.

Directives save and restore grid state across page reloads.

LocalStorageStore is used by default. Switch to QueryParamsStore if needed.

The kbqAgGridColumnState directive saves sort order, column order, visibility, and width. Add it with a unique key and connect the store provider via kbqAgGridColumnStateStoreProvider.

The kbqAgGridFilterState directive saves column filter models. Add it with a unique key and connect the store provider via kbqAgGridFilterStateStoreProvider.

The kbqAgGridQuickFilterState directive saves the quick filter value. Add it with a unique key, connect the store provider via kbqAgGridQuickFilterStateStoreProvider, and bind the input value via [(kbqAgGridQuickFilterStateValue)].

The kbqAgGridExternalFilterState directive saves the external filter value. Add it with a unique key, connect the store provider via kbqAgGridExternalFilterStateStoreProvider, bind the value via [(kbqAgGridExternalFilterStateValue)], and pass the row check function via kbqAgGridExternalFilterStatePass.

The kbqAgGridRowSelectionState directive saves row selection. Add it with a unique key, connect the store provider via kbqAgGridRowSelectionStateStoreProvider, and set getRowId.

The kbqAgGridRowFocusState directive saves the focused cell. Add it with a unique key, connect the store provider via kbqAgGridRowFocusStateStoreProvider, and set getRowId.

The kbqAgGridSettingsMenu directive adds a table settings button in the top-right corner of the grid. By default, the menu contains two items:

ItemDescription
kbqAgGridSettingsMenuColumnsItem()Showing, hiding, reordering and pinning columns, searching by name
kbqAgGridSettingsMenuSortItem()Sorting by several columns

The reset button restores the columns and the sorting to their initial state.

Constraints are configured via ColDef:

  • lockVisible: true prevents hiding a column. The last visible column can never be hidden regardless.
  • lockPinned: true prevents pinning and unpinning a column.

Russian labels are used by default. To switch the language, provide the labels providers:

providers: [
    kbqAgGridSettingsMenuLabelsProvider(KBQ_AG_GRID_SETTINGS_MENU_LABELS_EN),
    kbqAgGridColumnMenuLabelsProvider(KBQ_AG_GRID_COLUMN_MENU_LABELS_EN)
];

The kbqAgGridLoadingOverlay directive controls the grid loading state: when the value is true, a skeleton overlay is shown on top of the rows.

The skeleton placeholder takes the place of the grid before loading. Regardless of the contents of the future grid, the placeholder consists of a header, 3 columns and 3 rows. The number of columns and rows can be adjusted via kbqAgGridLoadingOverlayConfigProvider. The first column has a fixed size, the rest stretch equally. The placeholder bars in the cells imitate the real content and have different widths.

After the grid is initialized, the data starts loading. For consistency, the placeholder of three rows stays during loading, but now it reflects the real set of columns and their widths, and the selection column. The placeholder bars in the cells still have different widths to imitate the real content.

KbqAgGridSkeletonCellRenderer shows a skeleton in cells of rows the infinite row model (rowModelType="infinite") has not loaded yet. The selection column has its own skeleton: while there is no data, the checkbox is unavailable.

On the initial load, the grid immediately requests the first and the second portions of data, and while scrolling it stays one step ahead of the user.

If a portion fails to load, the kbqAgGridLoadError directive shows an error message with a retry link on the last row:

  • the message scrolls vertically together with the rows;
  • during horizontal scrolling, the message stays in the visible area of the grid;
  • the message takes up the whole visible area of the grid, even with pinned columns;
  • if row dividers appear or the row height changes, the message adapts to the overall styling.

To see these cases in the example, switch the options under the grid.

If the grid has no skeletons, a text loading indicator can be shown while data is loading. It spans the whole row width, so the selection column does not shift its label.

With infinite scrolling, data is loaded in blocks, so it is not possible to select all rows using a regular list — most of them are not yet loaded. The kbqAgGridInfiniteSelection directive inverts the selection: instead of a list of selected rows, it stores an "all selected" flag and a list of exceptions.

This state mirrors the condition "all except the specified IDs", so it can be passed to the server without loading all rows.

The directive requires two parameters:

  • kbqAgGridInfiniteSelectionDatasource accepts a data source. When all rows are selected, newly loaded blocks are automatically added to the selection.
  • getRowId returns a stable unique row identifier.

You can add custom keyboard shortcuts by adding the appropriate directives to your <ag-grid-angular> component.

Key
ActionDirective
TabMove to next rowkbqAgGridToNextRowByTab
Shift + ↓↑Select multiple rowskbqAgGridSelectRowsByShiftArrow
Ctrl + clickSelect a rowkbqAgGridSelectRowsByCtrlClick
Ctrl + CCopy selected rowskbqAgGridCopyByCtrlC
Shift + clickSelect a range of rowskbqAgGridSelectRowsByShiftClick
Ctrl + ASelect all rowskbqAgGridInfiniteSelection

More information about keyboard shortcuts can be found in the ag-grid-angular documentation.

  • Use the Table component for simple tables with a small amount of data that do not require resizing or reordering of columns.
  • If the list contains only one column, use List or Tree.
Suggestions for improvement
If you found a mistake or want to improve the article, create an issue on GitHub.