#useCurrentViewState
useCurrentViewState() is a composable that returns a ref of the state of the
active view — the entry in state.view.views whose id is
state.view.currentViewId. The ref gets a new value when the user switches
views or changes the current one (sorting, grouping, column order, selection,
…). Call it in <script setup> (or in setup()) of a component rendered
inside <Adaptable.Provider>.
import { useCurrentViewState } from '@adaptabletools/datagrid-vue';
const view = useCurrentViewState();The result is a read-only shallow ref (Readonly<ShallowRef<T>>). Its value is
the view as authored in state: an AdaptableTableView or an
AdaptablePivotView (pivot views have pivotColumns), or undefined when no
view matches. See Views for the view properties.
It is a shorthand for:
const view = useAdaptableState((state) =>
state.view.views.find((v) => v.id === state.view.currentViewId),
);#Usage
Read view.value in the script; the template unwraps the ref.
<script setup lang="ts">
import { useCurrentViewState } from '@adaptabletools/datagrid-vue';
const view = useCurrentViewState();
</script>
<template>
<div>Current view: {{ view?.label ?? 'None' }}</div>
</template><Adaptable.Provider
adaptableId="my-app"
primaryKey="id"
:data="data"
:defaultState="defaultState"
>
<CurrentViewLabel />
<Adaptable.UI />
</Adaptable.Provider>To change the view, use useViews() (which also returns currentView) or
adaptableApi.viewApi.setActiveView(viewId) — see
useAdaptableApi.
The panel above the grid shows the label, the type, the sorting and the group columns of the active view.
Switch the view from the dashboard, or click a column header to change the sorting, and watch the panel update.