#Hooks
Adaptable exposes its state and API to your own Vue components through composables. Each one has the name of the React hook it matches, so this section keeps the name "hooks".
Call a composable in <script setup> (or in setup()) 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.
<script setup lang="ts">
import { useCurrentViewState } from '@adaptabletools/datagrid-vue';
// a ref of the current view
const view = useCurrentViewState();
</script>
<template>
<div>Current view: {{ view?.label ?? view?.id }}</div>
</template><Adaptable.Provider v-bind="props">
<CurrentViewLabel />
<Adaptable.UI />
</Adaptable.Provider>All composables are named exports of @adaptabletools/datagrid-vue.
#What a composable returns
useAdaptableApi(),useAdaptableActions()anduseAdaptableId()return the value itself, not a ref.useAdaptableStateSubscribe()returns nothing.useAdaptableState(),useCurrentViewState(),useCellSelection()anduseRowSelection()return a read-only shallow ref (Readonly<ShallowRef<T>>) of the value described below.useVisibleColumns()and every other composable on this page return a computed ref (ComputedRef<T>) of what is described below — for most of them one object with the values and the functions:const views = useViews(), thenviews.value.currentViewandviews.value.setActiveView(viewId).
Read .value in the script; a template unwraps a ref held in a top-level
variable of <script setup>. Read it where it is used — in the template, a
computed, a watch or an event handler: what is taken out of .value
directly in setup is the value of that moment and does not follow the state.
The state is not made deeply reactive: a ref gets a new value when the state it
reads changes.
#State and API
useAdaptableApi()— returns theAdaptableApiof the enclosing provider.useAdaptableState(selector?)— returns a ref of the whole Adaptable state, or of the slice picked byselector.useAdaptableStateSubscribe({ selector, callback, equals? })— callscallback(value, oldValue, context)whenever the selected slice changes, until the component is unmounted.useAdaptableActions()— returns the internal action dispatchers (viewActions,configActions, …). PreferuseAdaptableApiin application code.useAdaptableId()— returns theadaptableIdof the enclosing provider.
#Current view and selection
useCurrentViewState()— returns the state of the active view (table or pivot), orundefined.useVisibleColumns()— returns the visible columns of the current table view, in view order; an empty array for pivot views.useCellSelection()— returns{ columnIds, positions }for the selected cells, ornullwhen nothing is selected.useRowSelection<T>()— returns the selected rows as row info objects, ornullwhen the view has no row selection.useViewSelection()— 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 composables operate on the current view. They power the built-in settings panel editors, so you can use them to build your own.
useViews()—views,currentViewId,currentView, plussetActiveView,createTableView,createPivotView,cloneView,deleteViewandrenameView.useViewColumns()— the columns of the current table view (including hidden and group columns),availableColumns,columnsNotInView, plussetColumnOrder,setColumnVisible,addColumn,removeColumn,setColumnsInView,setColumnModelandpatchColumn.useColumnSizing()— the view columns plussetColumnSizing(columnId, { width, flex, minWidth, maxWidth }); passnullto clear a field.useColumnPinning()— the view columns plussetColumnPinned(columnId, pinned).useColumnLabels()— the view columns (each with itslabelanddefaultLabel) plussetColumnLabel(columnId, label); an empty label ornullrestores the default.useColumnProperties()— 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.useColumnSorting()—sorting(in priority order),sortableColumns,singleColumnSort, plussetSorting(sorting)andsetSort(columnId, dir | null).useColumnGrouping()—groupColumns,groupedColumnIds,groupableColumns, the renderstrategy('single-column' | 'multiple-columns'), plusaddGroupByColumn,removeGroupByColumn,setGrouping,clearGrouping,setStrategyandsetGroupColumnField. Table views only.useColumnAggregations()—aggregatableColumns,aggregations, plussetAggregation(columnId, aggregation),setAggregations(record)andgetAggregationOptions(column). Works for table and pivot views.useAggregationTypes()—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.useCalculatedColumns()—calculatedColumns, pluscreateCalculatedColumn,updateCalculatedColumn,deleteCalculatedColumn,addToCurrentView,removeFromCurrentViewandgetDataTypeFromExpression. See Calculated Columns.
#Filtering and search
useGridFilter()—gridFilter(the AQL expression,''when none),isPaused, plussetGridFilter,clearGridFilter,setPausedandisValidGridFilter. See Grid Filter.useColumnFilters()—columnFilters(expression, column, paused state, error), plusaddColumnFilter,setColumnFilter,removeColumnFilter,clearColumnFilters,setPausedandsetAllPaused. See Column Filters.useNamedQueries()—namedQueries, pluscreateNamedQuery,updateNamedQuery,deleteNamedQuery,getNamedQueryByNameandgetReference(name)(returnsQUERY("name")).useQuickSearchConfig()— the quick searchconfigandupdateConfig(patch). See Quick Search.
For custom column filter editors, useColumnFilterEditor() and
useColumnFilterValues(() => options) give you the editor context and the
pickable values of a column. useColumnFilterValues takes a function that
returns the options, so that the options can change.
#Pivoting
usePivotColumns()—pivotColumns,pivotableColumns,showTotalColumns, plussetPivotColumns,addPivotColumn,removePivotColumnandsetShowTotalColumns. See Pivot Views.usePivotGrouping()— the same shape asuseColumnGrouping, for the row groups of the current pivot view.
#Styling, alerts and export
useStyledCells()—styledCells,currentViewStyledCellIds, pluscreateStyledCell,updateStyledCell,deleteStyledCell,addToCurrentView,removeFromCurrentViewandsetCurrentViewStyledCells. See Styled Cells.useFlashingCells()— the same shape for flashing cells (flashingCells,createFlashingCell, …). See Flashing Cells.useAlerts()—alerts,customActions, pluscreateAlert,updateAlertanddeleteAlert. See Alerts.useCellNotes()—threads,allThreads,unreadCount,unreadMentions,getThreads(filter), plus the open popover target. Mutations go throughadaptableApi.cellNoteApi. See Cell Notes.useReports()—reports,destinations, pluscreateReport,updateReport,deleteReportandrunReport(reportId, destination).useTheme()—themes,currentThemeId,accentColors,currentAccentColor, plussetThemeandsetAccentColor. See Theming.