#useAdaptableApi
useAdaptableApi() returns the AdaptableApi of the enclosing
<Adaptable.Provider />. Use it in any component rendered inside the provider
to act on the grid imperatively — switch views, set the quick search text,
change the theme, add or update rows, and so on.
In Vue it is a composable: call it in <script setup> (or in setup()). It
returns the API object itself, not a ref.
<script setup lang="ts">
import { components, useAdaptableApi } from '@adaptabletools/datagrid-vue';
const { Button } = components;
const api = useAdaptableApi();
</script>
<template>
<div class="flex flex-row gap-2 p-2">
<Button tone="accent" @click="api.viewApi.setActiveView('by-salary')">By salary</Button>
<Button tone="accent" @click="api.viewApi.setActiveView('all')">All developers</Button>
<Button tone="neutral" @click="api.themeApi.setTheme('dark')">Dark theme</Button>
<Button tone="neutral" @click="api.themeApi.setTheme('light')">Light theme</Button>
</div>
</template><Adaptable.Provider
adaptableId="docs-hooks-use-adaptable-api"
primaryKey="id"
:data="data"
:defaultState="defaultState"
>
<Toolbar />
<Adaptable.UI />
</Adaptable.Provider>The API is grouped by feature: viewApi, quickSearchApi, themeApi,
dataSourceApi, filterApi, styledCellsApi, alertApi, exportApi,
settingsPanelApi, stateApi and more. Pass your row type to get typed data
access: useAdaptableApi<Developer>().
The API object itself does not change and is not reactive: a template or a
computed that reads from it is not updated when the state changes. To read
state reactively, combine it with
useAdaptableState or one of the
feature composables.
Outside of a component's setup, get the same object from the
onReady callback prop:
<script setup lang="ts">
import {
Adaptable,
type AdaptableProps,
type AdaptableReadyContext,
} from '@adaptabletools/datagrid-vue';
declare const props: AdaptableProps;
const onReady = ({ adaptableApi }: AdaptableReadyContext) => {
adaptableApi.quickSearchApi.setSearchText('Python');
};
</script>
<template>
<Adaptable.Provider v-bind="props" :onReady="onReady" />
</template>The buttons call api.viewApi.setActiveView and
api.quickSearchApi.setSearchText. The label next to them reads the current
view with useCurrentViewState, so it updates as you switch views.