#Hooks
Adaptable exposes its state and API to your own React components through hooks.
Every hook works in any component rendered inside <Adaptable.Provider /> —
next to <Adaptable.UI />, inside a custom column header, in a toolbar, or in a
custom InfiniteTable component.
import { Adaptable, useCurrentViewState } from '@adaptabletools/datagrid-react';
function CurrentViewLabel() {
const view = useCurrentViewState();
return <div>Current view: {view?.label ?? view?.id}</div>;
}
export function App() {
return (
<Adaptable.Provider {...props}>
<CurrentViewLabel />
<Adaptable.UI />
</Adaptable.Provider>
);
}All hooks are named exports of @adaptabletools/datagrid-react.
#State and API
useAdaptableApi()— returns theAdaptableApiof the enclosing provider.useAdaptableState(selector?)— returns the whole Adaptable state, or the slice picked byselector, and re-renders when it changes.useAdaptableStateSubscribe({ selector, callback, equals? })— callscallback(value, oldValue, context)whenever the selected slice changes, without re-rendering.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 hooks 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.
#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.