Adaptable

#Hooks

Adaptable exposes its state and API to your own Angular components through inject functions. Each one is named after the React hook it matches, with inject in place of use (useViews() is injectViews()), so this section keeps the name "hooks".

Call an inject function in an injection context — a field initializer or the constructor — of any component rendered inside <adaptable-provider>: next to <adaptable-ui />, inside a custom column header, in a toolbar, or in a custom InfiniteTable component. Write the component inside <adaptable-provider> in the template that has the provider: content that your own wrapper component projects keeps the injector of the page and does not see the provider.

A component that reads the current view
import { Component } from '@angular/core';
import {
  AdaptableProvider,
  AdaptableUI,
  injectCurrentViewState,
} from '@adaptabletools/datagrid-angular';

@Component({
  selector: 'current-view-label',
  template: `<div>Current view: {{ view()?.label ?? view()?.id }}</div>`,
})
class CurrentViewLabel {
  // a signal of the current view
  protected readonly view = injectCurrentViewState();
}

@Component({
  selector: 'app-root',
  imports: [AdaptableProvider, AdaptableUI, CurrentViewLabel],
  template: `
    <adaptable-provider adaptableId="app" primaryKey="id" [data]="data" [defaultState]="defaultState">
      <current-view-label />
      <adaptable-ui />
    </adaptable-provider>
  `,
})
export class App {
  protected readonly data = data;
  protected readonly defaultState = defaultState;
}

All inject functions are named exports of @adaptabletools/datagrid-angular.

#What an inject function returns

  • injectAdaptableStateSubscribe() returns nothing.
  • Every other one returns a read-only Signal of what is described below — for most of them one object with the values and the functions: const views = injectViews(), then views().currentView and views().setActiveView(viewId). The signals of injectAdaptableApi(), injectAdaptableActions() and injectAdaptableId() do not change.

Read a signal where it is used — in the template, a computed, an effect or an event handler. The provider sets itself up in its ngOnInit, after the components inside it are created: read the signals from your component's ngOnInit on, not in its constructor. The state is not copied into signals: a signal gets a new value when the part of the state it reads changes.

#State and API

#Current view and selection

  • injectCurrentViewState() — returns the state of the active view (table or pivot), or undefined.
  • injectVisibleColumns() — returns the visible columns of the current table view, in view order; an empty array for pivot views.
  • injectCellSelection() — returns { columnIds, positions } for the selected cells, or null when nothing is selected.
  • injectRowSelection<T>() — returns the selected rows as row info objects, or null when the view has no row selection.
  • injectViewSelection() — the effective selection mode and keyboardNavigation of the current view, the columns that can show the selection checkbox, plus setMode, setKeyboardNavigation ('auto' follows the mode), setSelectionColumn and multiSelectTarget / setMultiSelectTarget. See Selection and Keyboard navigation.

#Views and columns

These inject functions operate on the current view. They power the built-in settings panel editors, so you can use them to build your own.

  • injectViews() — views, currentViewId, currentView, plus setActiveView, createTableView, createPivotView, cloneView, deleteView and renameView.
  • injectViewColumns() — the columns of the current table view (including hidden and group columns), availableColumns, columnsNotInView, plus setColumnOrder, setColumnVisible, addColumn, removeColumn, setColumnsInView, setColumnModel and patchColumn.
  • injectColumnSizing() — the view columns plus setColumnSizing(columnId, { width, flex, minWidth, maxWidth }); pass null to clear a field.
  • injectColumnPinning() — the view columns plus setColumnPinned(columnId, pinned).
  • injectColumnLabels() — the view columns (each with its label and defaultLabel) plus setColumnLabel(columnId, label); an empty label or null restores the default.
  • injectColumnProperties() — the view columns (each with its definition and the view's override) plus getProperty(columnId, key) ({ value, inherited, overridden }), setProperty(columnId, key, value) (null or the inherited value removes the override), isColumnOverridden(columnId) and resetColumn(columnId). It powers the column inspector on the Columns settings page. See Editing columns in the UI.
  • injectColumnSorting() — sorting (in priority order), sortableColumns, singleColumnSort, plus setSorting(sorting) and setSort(columnId, dir | null).
  • injectColumnGrouping() — groupColumns, groupedColumnIds, groupableColumns, the render strategy ('single-column' | 'multiple-columns'), plus addGroupByColumn, removeGroupByColumn, setGrouping, clearGrouping, setStrategy and setGroupColumnField. Table views only.
  • injectColumnAggregations() — aggregatableColumns, aggregations, plus setAggregation(columnId, aggregation), setAggregations(record) and getAggregationOptions(column). Works for table and pivot views.
  • injectAggregationTypes() — customAggregationTypes (the AdaptableQL aggregation types of the current view defined in state, each with allViews), plus saveAggregationType(id, config, { allViews }), deleteAggregationType(id, { allViews }) and getUniqueId(label). See Editing aggregations in the UI.
  • injectCalculatedColumns() — calculatedColumns, plus createCalculatedColumn, updateCalculatedColumn, deleteCalculatedColumn, addToCurrentView, removeFromCurrentView and getDataTypeFromExpression. See Calculated Columns.
  • injectGridFilter() — gridFilter (the AQL expression, '' when none), isPaused, plus setGridFilter, clearGridFilter, setPaused and isValidGridFilter. See Grid Filter.
  • injectColumnFilters() — columnFilters (expression, column, paused state, error), plus addColumnFilter, setColumnFilter, removeColumnFilter, clearColumnFilters, setPaused and setAllPaused. See Column Filters.
  • injectNamedQueries() — namedQueries, plus createNamedQuery, updateNamedQuery, deleteNamedQuery, getNamedQueryByName and getReference(name) (returns QUERY("name")).
  • injectQuickSearchConfig() — the quick search config and updateConfig(patch). See Quick Search.

For custom column filter editors, injectColumnFilterEditor() and injectColumnFilterValues(() => options) give you signals of the editor context and of the pickable values of a column. injectColumnFilterValues takes a function that returns the options, so that the options can change: it can read your signals.

#Pivoting

  • injectPivotColumns() — pivotColumns, pivotableColumns, showTotalColumns, plus setPivotColumns, addPivotColumn, removePivotColumn and setShowTotalColumns. See Pivot Views.
  • injectPivotGrouping() — the same shape as injectColumnGrouping, for the row groups of the current pivot view.

#Styling, alerts and export

  • injectStyledCells() — styledCells, currentViewStyledCellIds, plus createStyledCell, updateStyledCell, deleteStyledCell, addToCurrentView, removeFromCurrentView and setCurrentViewStyledCells. See Styled Cells.
  • injectFlashingCells() — the same shape for flashing cells (flashingCells, createFlashingCell, …). See Flashing Cells.
  • injectAlerts() — alerts, customActions, plus createAlert, updateAlert and deleteAlert. See Alerts.
  • injectCellNotes() — threads, allThreads, unreadCount, unreadMentions, getThreads(filter), plus the open popover target. Mutations go through adaptableApi.cellNoteApi. See Cell Notes.
  • injectReports() — reports, destinations, plus createReport, updateReport, deleteReport and runReport(reportId, destination).
  • injectTheme() — themes, currentThemeId, accentColors, currentAccentColor, plus setTheme and setAccentColor. See Theming.