Could someone tell me why the loader control does not hide and stays in the dialog indefinitely? Even after fetching the data and toggling the visibility of the control to false? I noticed that it disappears only after zooming out of the browser?
Here is my simple code:
@page "/fetchdata"@using Telerik.Blazor;
@using Telerik.Blazor.Components;
@using Telerik.DataSource;
@using Telerik.FontIcons
@using Telerik.SvgIcons;
@using Telerik.DataSource.Extensions;
<TelerikButton OnClick="@OpenDialogRequestHandler">Click me to open dialog</TelerikButton>
<TelerikDialog
@bind-Visible="@DialogVisibility"
ShowCloseButton="true"
CloseOnOverlayClick="true"
Title="Test"
Height="300">
<DialogContent>
<TelerikLoaderContainer
OverlayThemeColor="light"
Visible="@(ApiDataRequestInProgress)"
Class="initial-data-loader"
LoaderType="@LoaderType.InfiniteSpinner"
Size="@(ThemeConstants.Loader.Size.Medium)">
</TelerikLoaderContainer>
<TelerikGrid
EnableLoaderContainer="false"
Sortable="true"
OnRead="@GridReadHandler"
TItem="TestObject"
Height="500px"
Width="300px" Data="_testData"
SelectionMode="GridSelectionMode.Single">
<GridColumns>
<GridColumn Field="@nameof(TestObject.Gid)" Visible="false" Width="0" />
<GridColumn Field="@nameof(TestObject.TestProperty)" Title="Treść" Width="100%" />
</GridColumns>
</TelerikGrid>
</DialogContent>
</TelerikDialog>
@code {
bool _dataInitiated = false;
bool _refreshing = false;
List<TestObject> _testData = new List<TestObject>();
async Task GridReadHandler(GridReadEventArgs args)
{
if (!_dataInitiated)
{
// I don't want to download data in the OnInitialized method because if the form contains a
// lot of such fields, the page loading will slow down terribly. And this data is only needed
// if the user opens a dialog box (clicks a button). Otherwise there is no point in downloading them.
await MakeAPIRequestAsync();
_dataInitiated = true;
}
DataSourceResult result = _testData.ToDataSourceResult(args.Request);
args.Data = result.Data;
args.Total = result.Total;
StateHasChanged();
}
void OpenDialogRequestHandler()
{
DialogVisibility = true;
}
async Task MakeAPIRequestAsync(bool pCzyNieUzywacCache = false)
{
try
{
// Simulate API request
await Task.Delay(1000);
_testData.Clear();
_testData.Add(new TestObject() { TestProperty = "Alice" });
_testData.Add(new TestObject() { TestProperty = "Has" });
_testData.Add(new TestObject() { TestProperty = "A" });
_testData.Add(new TestObject() { TestProperty = "Cat" });
}
finally
{
ApiDataRequestInProgress = false;
}
}
public bool ApiDataRequestInProgress { get; set; } = true;
public bool DialogVisibility { get; set; } = false;
internal class TestObject
{
public Guid Gid { get; set; } = Guid.NewGuid();
public string TestProperty { get; set; } = string.Empty;
}
}