#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.
import { Adaptable, useAdaptableApi } from '@adaptabletools/datagrid-react';
function Toolbar() {
const api = useAdaptableApi();
return (
<div className="flex flex-row gap-2 p-2">
<Button onClick={() => api.viewApi.setActiveView('by-salary')} variant="accent">
By salary
</Button>
<Button onClick={() => api.viewApi.setActiveView('all')} variant="accent">
All developers
</Button>
<Button onClick={() => api.themeApi.setTheme('dark')}>Dark theme</Button>
<Button onClick={() => api.themeApi.setTheme('light')}>Light theme</Button>
</div>
);
}
export default function App() {
return (
<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, so this hook does not re-render your component when the state changes. To read state reactively, combine it with useAdaptableState or one of the feature hooks.
Outside of React components, get the same object from the
onReady callback prop:
<Adaptable.Provider
{...props}
onReady={({ adaptableApi }) => {
adaptableApi.quickSearchApi.setSearchText('Python');
}}
/>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.