Hi Andrey,
Thanks for contacting Syncfusion support!
We have validated your reported scenario as “Removed the old tab item content from DOM when selecting new tab item”. The Blazor Tabs load its content freshly on navigating tab instead of display as none.
So, we suggest you to follow below steps to keep the state of tab content.
Step1: Add a class in project to maintain a state. For example we added a class called “CounterState.cs” using below code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TabComponent
{
public class CounterState
{
public int CurrentCount { get; set; }
}
} |
Step2: Need to register the above class by opening the Startup.cs file and adding the following code to the end of the ConfigureServices method as like below:
// ** SESSION STATE
// Singleton usually means for all users,
// where as scoped means for the current unit-of-work
services.AddScoped<CounterState>();
|
Step3: To consume that class, need to inject the class name in “Index.razor” file and refer the below code for that
@inject CounterState CounterState
<EjsTab>
---------
----------
<ContentTemplate>
<div class="active">
<input value="@CounterState.CurrentCount" /> // Get input value
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
</div>
</ContentTemplate>
-----------
-----------
</EjsTab>
@code{
public void IncrementCount()
{
int CurrentCount = CounterState.CurrentCount; // set session state
CurrentCount++;
CounterState.CurrentCount = CurrentCount; // set current count on session state object
}
} |
So, Please try out this sample and We hope that the old value could be persisted whenever you selecting new tab item. You can also download this sample from the following link
Also, we have already logged improvement as "Load tab content when required but keep the content once it's rendered" to maintain the state in Tabs which will be available on 2020, Vol 1 main release. You can track the following link for that
Kindly Let us know, if you need further assistance.
Regards
Alagumeena.K