DatAInsightsComposer State
The Telerik DatAInsightsComposer for Blazor exposes state management capabilities through methods. Use them to get, save, and programmatically manipulate the DatAInsightsComposer state, including the configuration of already generated components.
Objects
The DatAInsightsComposer stores its state in the following objects:
DatAInsightsComposerState—the state of the DatAInsightsComposer and all generated components together with their history items.ComponentConfigSectionState—the state of a specific component and its history items.
Methods
The GetState and SetState methods of the DatAInsightsComposer instance let you obtain or update the current DatAInsightsComposer state on demand at any time in or after OnAfterRenderAsync.
To make changes to the DatAInsightsComposer state:
- Get the current state with the
GetStatemethod. - Apply the desired modifications to the obtained
DatAInsightsComposerStateobject. - Set the modified state object through the
SetStatemethod.
To reset the DatAInsightsComposer state, call the SetState method and pass a new DatAInsightsComposerState instance as an argument.
Example
The following example demonstrates how to:
- Modify the
Promptand GridHeightthrough the DatAInsightsComposer state. Setting thePromptin the state firesPromptChanged, so that the app also updates the parameter value. Alternatively, you can directly set the DatAInsightsComposerPromptparameter. - Reset the DatAInsightsComposer state and remove any generated components and history items.
Reset or modify the DatAInsightsComposer state
<TelerikButton OnClick="@UpdateDAICState">Update DAIC State</TelerikButton>
<TelerikButton OnClick="@ResetDAICState">Reset DAIC State</TelerikButton>
<TelerikDatAInsightsComposer @ref="@DAICRef"
@bind-Prompt="@DAICPrompt" />
@code {
private TelerikDatAInsightsComposer? DAICRef;
private string DAICPrompt { get; set; } = string.Empty;
private async Task UpdateDAICState()
{
if (DAICRef is null)
{
return;
}
DatAInsightsComposerState daicState = DAICRef.GetState();
daicState.Prompt = "New programmatic prompt";
GridComponentConfig? gridConfig = daicState.Components.FirstOrDefault(x => x.ComponentConfig?.ComponentType == ComponentType.Grid)?.ComponentConfig as GridComponentConfig;
if (gridConfig is not null)
{
gridConfig.Config.PageSize = 5;
gridConfig.Config.Height = "auto";
}
await DAICRef.SetStateAsync(daicState);
}
private async Task ResetDAICState()
{
if (DAICRef is null)
{
return;
}
DatAInsightsComposerState newDAICState = new DatAInsightsComposerState();
await DAICRef.SetStateAsync(newDAICState);
}
}