#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.
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
Signalof what is described below — for most of them one object with the values and the functions:const views = injectViews(), thenviews().currentViewandviews().setActiveView(viewId). The signals ofinjectAdaptableApi(),injectAdaptableActions()andinjectAdaptableId()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
injectAdaptableApi()— returns a signal of theAdaptableApiof the enclosing provider.injectAdaptableState(selector?)— returns a signal of the whole Adaptable state, or of the slice picked byselector.injectAdaptableStateSubscribe({ selector, callback, equals? })— callscallback(value, oldValue, context)whenever the selected slice changes, until the component is destroyed.injectAdaptableActions()— returns a signal of the internal action dispatchers (viewActions,configActions, …). PreferinjectAdaptableApiin application code.injectAdaptableId()— returns a signal of theadaptableIdof the enclosing provider.
#Current view and selection
injectCurrentViewState()— returns the state of the active view (table or pivot), orundefined.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, ornullwhen nothing is selected.injectRowSelection<T>()— returns the selected rows as row info objects, ornullwhen the view has no row selection.injectViewSelection()— the effective selectionmodeandkeyboardNavigationof the current view, the columns that can show the selection checkbox, plussetMode,setKeyboardNavigation('auto'follows the mode),setSelectionColumnandmultiSelectTarget/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, plussetActiveView,createTableView,createPivotView,cloneView,deleteViewandrenameView.injectViewColumns()— the columns of the current table view (including hidden and group columns),availableColumns,columnsNotInView, plussetColumnOrder,setColumnVisible,addColumn,removeColumn,setColumnsInView,setColumnModelandpatchColumn.injectColumnSizing()— the view columns plussetColumnSizing(columnId, { width, flex, minWidth, maxWidth }); passnullto clear a field.injectColumnPinning()— the view columns plussetColumnPinned(columnId, pinned).injectColumnLabels()— the view columns (each with itslabelanddefaultLabel) plussetColumnLabel(columnId, label); an empty label ornullrestores the default.injectColumnProperties()— the view columns (each with itsdefinitionand the view'soverride) plusgetProperty(columnId, key)({ value, inherited, overridden }),setProperty(columnId, key, value)(nullor the inherited value removes the override),isColumnOverridden(columnId)andresetColumn(columnId). It powers the column inspector on the Columns settings page. See Editing columns in the UI.injectColumnSorting()—sorting(in priority order),sortableColumns,singleColumnSort, plussetSorting(sorting)andsetSort(columnId, dir | null).injectColumnGrouping()—groupColumns,groupedColumnIds,groupableColumns, the renderstrategy('single-column' | 'multiple-columns'), plusaddGroupByColumn,removeGroupByColumn,setGrouping,clearGrouping,setStrategyandsetGroupColumnField. Table views only.injectColumnAggregations()—aggregatableColumns,aggregations, plussetAggregation(columnId, aggregation),setAggregations(record)andgetAggregationOptions(column). Works for table and pivot views.injectAggregationTypes()—customAggregationTypes(the AdaptableQL aggregation types of the current view defined in state, each withallViews), plussaveAggregationType(id, config, { allViews }),deleteAggregationType(id, { allViews })andgetUniqueId(label). See Editing aggregations in the UI.injectCalculatedColumns()—calculatedColumns, pluscreateCalculatedColumn,updateCalculatedColumn,deleteCalculatedColumn,addToCurrentView,removeFromCurrentViewandgetDataTypeFromExpression. See Calculated Columns.
#Filtering and search
injectGridFilter()—gridFilter(the AQL expression,''when none),isPaused, plussetGridFilter,clearGridFilter,setPausedandisValidGridFilter. See Grid Filter.injectColumnFilters()—columnFilters(expression, column, paused state, error), plusaddColumnFilter,setColumnFilter,removeColumnFilter,clearColumnFilters,setPausedandsetAllPaused. See Column Filters.injectNamedQueries()—namedQueries, pluscreateNamedQuery,updateNamedQuery,deleteNamedQuery,getNamedQueryByNameandgetReference(name)(returnsQUERY("name")).injectQuickSearchConfig()— the quick searchconfigandupdateConfig(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, plussetPivotColumns,addPivotColumn,removePivotColumnandsetShowTotalColumns. See Pivot Views.injectPivotGrouping()— the same shape asinjectColumnGrouping, for the row groups of the current pivot view.
#Styling, alerts and export
injectStyledCells()—styledCells,currentViewStyledCellIds, pluscreateStyledCell,updateStyledCell,deleteStyledCell,addToCurrentView,removeFromCurrentViewandsetCurrentViewStyledCells. See Styled Cells.injectFlashingCells()— the same shape for flashing cells (flashingCells,createFlashingCell, …). See Flashing Cells.injectAlerts()—alerts,customActions, pluscreateAlert,updateAlertanddeleteAlert. See Alerts.injectCellNotes()—threads,allThreads,unreadCount,unreadMentions,getThreads(filter), plus the open popover target. Mutations go throughadaptableApi.cellNoteApi. See Cell Notes.injectReports()—reports,destinations, pluscreateReport,updateReport,deleteReportandrunReport(reportId, destination).injectTheme()—themes,currentThemeId,accentColors,currentAccentColor, plussetThemeandsetAccentColor. See Theming.