#useCurrentViewState
useCurrentViewState() returns the state of the active view — the entry in
state.view.views whose id is state.view.currentViewId — and re-renders your
component when the user switches views or changes the current one (sorting,
grouping, column order, selection, …).
import { useCurrentViewState } from '@adaptabletools/datagrid-react';
const view = useCurrentViewState();The result 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
import { Adaptable, useCurrentViewState } from '@adaptabletools/datagrid-react';
function CurrentViewLabel() {
const view = useCurrentViewState();
return <div>Current view: {view?.label ?? 'None'}</div>;
}
export function App() {
return (
<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.