#injectCurrentViewState
injectCurrentViewState() (the Angular counterpart of the
useCurrentViewState hook) returns a signal of the state of the active view —
the entry in state.view.views whose id is state.view.currentViewId. The
signal gets a new value when the user switches views or changes the current
one (sorting, grouping, column order, selection, …). Call it in an injection
context (a field initializer or the constructor) of a component rendered
inside <adaptable-provider>.
import { Component } from '@angular/core';
import { injectCurrentViewState } from '@adaptabletools/datagrid-angular';
// a component rendered inside <adaptable-provider>
@Component({ selector: 'current-view-name', template: '{{ view()?.label }}' })
export class CurrentViewName {
protected readonly view = injectCurrentViewState();
}The result is a read-only Signal. 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:
protected readonly view = injectAdaptableState((state) =>
state.view.views.find((v) => v.id === state.view.currentViewId),
);#Usage
Call view() to read the value, in the template and in the class.
import { Component } from '@angular/core';
import {
AdaptableProvider,
AdaptableUI,
injectCurrentViewState,
} from '@adaptabletools/datagrid-angular';
@Component({
selector: 'current-view-label',
template: `<div>Current view: {{ view()?.label ?? 'None' }}</div>`,
})
class CurrentViewLabel {
protected readonly view = injectCurrentViewState();
}
@Component({
selector: 'app-root',
imports: [AdaptableProvider, AdaptableUI, CurrentViewLabel],
template: `
<adaptable-provider
adaptableId="my-app"
primaryKey="id"
[data]="data"
[defaultState]="defaultState"
>
<current-view-label />
<adaptable-ui />
</adaptable-provider>
`,
})
export class App {
protected readonly data = data;
protected readonly defaultState = defaultState;
}To change the view, use injectViews() (which also returns currentView) or
adaptableApi.viewApi.setActiveView(viewId) — see
injectAdaptableApi.
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.