If the ComboBox Value is set during initialization and the ValueMapper executes too fast and before the component has rendered, its Value doesn't show.
The problem also occurs in the MultiColumnComboBox.
Possible workarounds:
To reproduce:
@using Telerik.DataSource
@using Telerik.DataSource.Extensions
<p>ComboBox Value: @ComboBoxValue</p>
<TelerikComboBox ItemHeight="30"
OnRead="@OnComboBoxRead"
PageSize="20"
ScrollMode="@DropDownScrollMode.Virtual"
TItem="@ListItem"
TValue="@(int?)"
@bind-Value="@ComboBoxValue"
ValueMapper="@ComboBoxValueMapper"
Width="240px" />
@code {
private List<ListItem>? ComboBoxData { get; set; }
private int? ComboBoxValue { get; set; } = 3;
private async Task OnComboBoxRead(ReadEventArgs args)
{
DataSourceResult result = await ComboBoxData.ToDataSourceResultAsync(args.Request);
args.Data = result.Data;
args.Total = result.Total;
}
private async Task<ListItem?> ComboBoxValueMapper(int? selectValue)
{
// Triggers the bug
await Task.Yield();
ListItem? result = ComboBoxData?.FirstOrDefault(x => selectValue == x.Value);
return result;
}
protected override void OnInitialized()
{
ComboBoxData = Enumerable
.Range(1, 1234)
.Select(x => new ListItem()
{
Value = x,
Text = $"Item {x}"
})
.ToList();
}
public class ListItem
{
public int Value { get; set; }
public string Text { get; set; } = string.Empty;
}
}