Adaptable

#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

#Current view and selection

  • useCurrentViewState() — returns the state of the active view (table or pivot), or undefined.
  • 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, or null when nothing is selected.
  • useRowSelection<T>() — returns the selected rows as row info objects, or null when the view has no row selection.
  • useViewSelection() — 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 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, plus setActiveView, createTableView, createPivotView, cloneView, deleteView and renameView.
  • useViewColumns() — the columns of the current table view (including hidden and group columns), availableColumns, columnsNotInView, plus setColumnOrder, setColumnVisible, addColumn, removeColumn, setColumnsInView, setColumnModel and patchColumn.
  • useColumnSizing() — the view columns plus setColumnSizing(columnId, { width, flex, minWidth, maxWidth }); pass null to clear a field.
  • useColumnPinning() — the view columns plus setColumnPinned(columnId, pinned).
  • useColumnLabels() — the view columns (each with its label and defaultLabel) plus setColumnLabel(columnId, label); an empty label or null restores the default.
  • useColumnProperties() — 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.
  • useColumnSorting() — sorting (in priority order), sortableColumns, singleColumnSort, plus setSorting(sorting) and setSort(columnId, dir | null).
  • useColumnGrouping() — groupColumns, groupedColumnIds, groupableColumns, the render strategy ('single-column' | 'multiple-columns'), plus addGroupByColumn, removeGroupByColumn, setGrouping, clearGrouping, setStrategy and setGroupColumnField. Table views only.
  • useColumnAggregations() — aggregatableColumns, aggregations, plus setAggregation(columnId, aggregation), setAggregations(record) and getAggregationOptions(column). Works for table and pivot views.
  • useAggregationTypes() — 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.
  • useCalculatedColumns() — calculatedColumns, plus createCalculatedColumn, updateCalculatedColumn, deleteCalculatedColumn, addToCurrentView, removeFromCurrentView and getDataTypeFromExpression. See Calculated Columns.
  • useGridFilter() — gridFilter (the AQL expression, '' when none), isPaused, plus setGridFilter, clearGridFilter, setPaused and isValidGridFilter. See Grid Filter.
  • useColumnFilters() — columnFilters (expression, column, paused state, error), plus addColumnFilter, setColumnFilter, removeColumnFilter, clearColumnFilters, setPaused and setAllPaused. See Column Filters.
  • useNamedQueries() — namedQueries, plus createNamedQuery, updateNamedQuery, deleteNamedQuery, getNamedQueryByName and getReference(name) (returns QUERY("name")).
  • useQuickSearchConfig() — the quick search config and updateConfig(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, plus setPivotColumns, addPivotColumn, removePivotColumn and setShowTotalColumns. See Pivot Views.
  • usePivotGrouping() — the same shape as useColumnGrouping, for the row groups of the current pivot view.

#Styling, alerts and export

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